#2d movement

1 messages · Page 1 of 1 (latest)

dreamy haven
#

@scenic briar

scenic briar
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMovement : MonoBehaviour
{

    Rigidbody2D rb;

    public float speed = 1;

    Vector2 veloc;

    int inputX;
    int inputY;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        veloc = rb.velocity;
        if (inputX != 0)
        {
            veloc.x = inputX * speed;
        } else
        {
            veloc.x = 0;
        }
        if (inputY != 0)
        {
            veloc.y = inputY * speed;
        } else
        {
            veloc.y = 0;
        }
        rb.velocity = veloc;
    }

    private void Update()
    {

        Vector2 veccy = transform.localScale;
        
        if (Input.GetAxis("Horizontal") > 0)
        {

            inputX = 1;
            veccy.x = -1;

        } else
        {
            inputX = 0;
        }

        if (Input.GetAxis("Horizontal") < 0)
        {

            inputX = -1;
            veccy.x = 1;

        }else
        {
            inputX = 0;
        }
        if (Input.GetAxis("Vertical") > 0)
        {

            inputY = 1;

        } else
        {
            inputY = 0;
        }

        if (Input.GetAxis("Vertical") < 0)
        {

            inputY = -1;

        } else { inputY = 0; }

            transform.localScale = veccy;
        

    }

}
``` this is what i have
dreamy haven
#

and use input get axis raw intead of getaxis

#

@scenic briar want me to send you the script it should look like and go over it?
or you do it, while i help?