0
\$\begingroup\$

Hey all I am trying to make a scene where the player is experiencing a plane crash however when I try and move the camera with transform. Translate the camera is not moving. The plane moves along as expected but the camera doesn't.

public class FlyPlane : MonoBehaviour  {

private GameObject walkPlane;
private GameObject playerController;


// Start is called before the first frame update
void Start()
{

    walkPlane = GameObject.Find("WalkPlane");
    playerController = GameObject.Find("Player");
}

// Update is called once per frame
void Update()
{
    transform.Translate(0,0,.1f); // actual flying plane
    walkPlane.transform.Translate(0,0,.1f);
    playerController.transform.Translate(0,0,.1f);
}}
\$\endgroup\$
7
  • 1
    \$\begingroup\$ Is FlyPlane the script that you are attaching to the camera? Where is the script that is actually supposed to move the camera? And btw, usually when you want to move anything, it is a good idea to create a Speed variable and multiply by Time.deltaTime, so you can control how fast you move per second instead of per frame. docs.unity3d.com/ScriptReference/Transform.Translate.html \$\endgroup\$
    – Fabio S.
    Feb 25, 2022 at 22:08
  • \$\begingroup\$ Does your PlayerController object have a script on it that's also controlling its movement, like a CharacterController? If so, you'll need to work in harmony with the changes it's making to the position, or disable it, rather than fighting with it for control. \$\endgroup\$
    – DMGregory
    Feb 25, 2022 at 22:13
  • \$\begingroup\$ This script is supposed to move the plane and camera, thanks for the link ill check it out ! \$\endgroup\$
    – Doug Ray
    Feb 26, 2022 at 1:32
  • \$\begingroup\$ I tried with the OVRPlayer controller and by just adding a basic camera in both cases the camera doesn't move \$\endgroup\$
    – Doug Ray
    Feb 26, 2022 at 1:33
  • \$\begingroup\$ I would recommend trying Mathf.MoveTowards() and rigidbody.MovePosition() instead of transform.Translate(). That usually cause problems for me \$\endgroup\$
    – Arian_ki
    Feb 26, 2022 at 4:41

0

You must log in to answer this question.

Browse other questions tagged .