4 Replies - 644 Views - Last Post: 13 October 2019 - 05:11 PM Rate Topic: -----

#1 protexxi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-November 14

Unity C# Bug

Posted 04 October 2019 - 03:39 PM

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.

public class BasicMovment : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        rigidbody = this.GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame

    public Animator animator;

    //public float movementSpeed = 1f;   //Movement Speed of the Player
    public Vector2 movement;           //Movement Axis
    public Rigidbody2D rigidbody;      //Player Rigidbody Component

    void Update()
    {

        animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
        animator.SetFloat("Vertical", Input.GetAxis("Vertical"));

        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");





    }

    void FixedUpdate()
    {
        rigidbody.MovePosition(rigidbody.position + movement *  Time.fixedDeltaTime);
    }


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!

Is This A Good Question/Topic? 0
  • +

Replies To: Unity C# Bug

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15493
  • View blog
  • Posts: 62,050
  • Joined: 12-June 08

Re: Unity C# Bug

Posted 04 October 2019 - 07:18 PM

How is it supposed to move?
Are you certain your math formula is working as you expect? Are you enforcing PEMDAS correctly?
Was This Post Helpful? 0
  • +
  • -

#3 protexxi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-November 14

Re: Unity C# Bug

Posted 05 October 2019 - 03:57 PM

Pressing The left arrow key will return a -1 so the maths with move - 1 moving the sprite to the left,

PEMBAS is a new phrase to me?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15493
  • View blog
  • Posts: 62,050
  • Joined: 12-June 08

Re: Unity C# Bug

Posted 05 October 2019 - 04:10 PM

https://en.m.wikiped...r_of_operations
Was This Post Helpful? 0
  • +
  • -

#5 protexxi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-November 14

Re: Unity C# Bug

Posted 13 October 2019 - 05:11 PM

the order of the maths is correct
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1