Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Follow camera: Player jumps on move

$
0
0
I am trying to create a follow camera. I have isolated the problem to the following simple setup: 1) Player object with rigidbody, no gravity, drag 4 and the following simple script public class playercontrol : MonoBehaviour { void FixedUpdate () { if (Input.GetKey (KeyCode.Space)) { rigidbody.velocity = transform.forward * 20; } } } 2) Camera with the following script public class cameracontrol : MonoBehaviour { public GameObject player; void FixedUpdate () { transform.position = player.transform.TransformPoint (new Vector3 (0f, 1.5f, -4f)); transform.rotation = player.transform.rotation; } } The intent is to have the camera always placed some distance behind the player. However, when i press the space key the player instantly jumps some distance forward, the camera follows it smoothly thereafter. When i release the space key the player slows down due to drag and, on the screen, it slowly moves backwards the distance that it jumped earlier. Now, if i change the camera function to `Update` instead `FixedUpdate` this problem doesn't occur. I understand the difference between `Update` and `FixedUpdate`, but i dont understand why the player would jump forward even when the camera is simply copying the position directly.

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>