I’m building a rail shooter type game where you the player is scripted to automatically move to various points on the map. I’m trying to use RigidBody.Moveposition to accomplish this, but I can’t seem to get it to work the way I want it to. I’d like to move the player to a coordinate that I give it, but for some reason movePosition only seems to work in update for augmenting the player’s existing position, not moving it. The code that I have is
public class Mover : MonoBehaviour {
//public float speed;
private Rigidbody rb;
// Use this for initialization
void Start () {
//Vector3 velocity = new Vector3(0f,0f,speed);
rb = GetComponent<Rigidbody>();
Vector3 newPos = new Vector3 (0f, 4f, 10f);
rb.MovePosition (newPos);
return;
}
void FixedUpdate () {
}
}
Where newPos is the position that I want to go to. Right now this code just seems to keep the player standing still. I know I could nudge it towards the position every frame with update, but that seems tedious and hard to work with. Is there a way to accomplish what I’m trying to do that works?