- Home /
Question by
M3nTh0LL · Dec 25, 2019 at 03:51 PM ·
player movementz-axis
What does influence the z-axis?,Why does influence the z axis?
https://imgur.com/a/qeMXXAm //video
Why does the player rotate like this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
private Rigidbody2D myRigidbody;
private Vector3 change;
private Animator animation;
// Start is called before the first frame update
void Start()
{
animation = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
change = Vector3.zero;
change.x = Input.GetAxisRaw("Horizontal");
change.y = Input.GetAxisRaw("Vertical");
UpdateAnimationAndMove();
}
void UpdateAnimationAndMove()
{
if (change != Vector3.zero)
{
MoveCharacter();
animation.SetFloat("moveX", change.x);
animation.SetFloat("moveY", change.y);
animation.SetBool("moving", true);
}
else
{
animation.SetBool("moving", false);
}
}
void MoveCharacter()
{
myRigidbody.MovePosition(transform.position + speed * change * Time.deltaTime);
}
}
Comment
Answer by jmaslaki · Dec 25, 2019 at 04:25 PM
In Rigidbody 2D, go to Constraints then select the Z box
Your answer
Follow this Question
Related Questions
How to set NavMeshAgent to move acording to own gameObject.tranform.forward? 1 Answer
Help Rotating a Player 0 Answers
3rd person camera-based player movement 0 Answers
how i can make player 2 go to follow my player again 0 Answers
Player wont move 3 Answers