Search Unity

Riigidbody.MovePosition automaticly starts spinning.

Discussion in 'Physics' started by cooldev607, Jan 11, 2020.

  1. cooldev607

    cooldev607

    Joined:
    Jan 11, 2020
    Posts:
    1
    I have just started learning how to use unity, and I would like to make smooth controls with ridigbodys. I have used the AddForce function, but I couldn't get that to stop moving after it started, so I researched a little bit and found the MovePosition function, but the thing is, it just starts automatically spinning. I would like to know how to use this function properly. Also this is my first time posting on this forum and please tell me if I should have posted this in the programming section. Thank you all very much.

    Here's my code:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class playerController : MonoBehaviour {
    4.     // I define this in the Inspector tab
    5.     public Rigidbody rb;
    6.  
    7.     void FixedUpdate() {
    8.         if (Input.GetKey("w")) {
    9.             Vector3 move = new Vector3(0, 0, 1) * forwardForce *Time.deltaTime;
    10.             rb.MovePosition(move);
    11.             Debug.Log("Moved using w key");
    12.  
    13.         }
    14.     }
    15. }
     
    Last edited: Jan 11, 2020