Search Unity

Strange Movement Bug

Discussion in 'Scripting' started by Protexxi, Oct 4, 2019.

  1. Protexxi

    Protexxi

    Joined:
    Oct 4, 2019
    Posts:
    7
    Hello, Although i have a decent amount of programming experience, i'm still getting my head around the unity API and have created the following code using a tutorial i found on the unity website.

    Code (CSharp):
    1. public class BasicMovment : MonoBehaviour
    2. {
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.         rigidbody = this.GetComponent<Rigidbody2D>();
    7.     }
    8.  
    9.     // Update is called once per frame
    10.  
    11.     public Animator animator;
    12.  
    13.     //public float movementSpeed = 1f;   //Movement Speed of the Player
    14.     public Vector2 movement;           //Movement Axis
    15.     public Rigidbody2D rigidbody;      //Player Rigidbody Component
    16.  
    17.     void Update()
    18.     {
    19.  
    20.         animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
    21.         animator.SetFloat("Vertical", Input.GetAxis("Vertical"));
    22.  
    23.         movement.x = Input.GetAxisRaw("Horizontal");
    24.         movement.y = Input.GetAxisRaw("Vertical");
    25.  
    26.  
    27.  
    28.  
    29.  
    30.     }
    31.  
    32.     void FixedUpdate()
    33.     {
    34.         rigidbody.MovePosition(rigidbody.position + movement *  Time.fixedDeltaTime);
    35.     }
    When i tested the code it works perfectly. However the asset the script is linked to walks slowly downwards been driving me nuts for hours now please send help!
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Hi and welcome!
    What exactly is the problem? From what you wrote, you created some movement script from a tutorial, posted its code, then claimed it works perfectly and said some asset i dont know is driving you nuts. Maybe it's just me, but i certainly cant help you with that explanation, as it appears nothing but the last sentence is relevant to your problem?