#2d movement
1 messages · Page 1 of 1 (latest)
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