Question by
Facepalmer_Bear · May 01 at 07:06 AM ·
c#physicsrigidbody
My Character is Not Moving
I discovered that my character is not moving, even though variables inputX and inputY have a value. The animator does work though. Can you spot a problem?
namespace Common.Scripts
{
public class BasicCharacter : MonoBehaviour
{
#region Constants
private static readonly int WALK_PROPERTY = Animator.StringToHash("Walk");
#endregion
#region Inspector
[SerializeField]
private float speed = 2f;
[Header("Relations")]
[SerializeField]
private Animator animator = null;
[SerializeField]
private Rigidbody physicsBody = null;
[SerializeField]
private SpriteRenderer spriteRenderer = null;
#endregion
#region Fields
private Vector3 _movement;
private manageJoystick _joystick;
private float inputX;
private float inputY;
#endregion
#region MonoBehaviour
void Update()
{
inputX = Input.GetAxis("Horizontal");
inputY = Input.GetAxis("Vertical");
//Walk
if (inputX == 0 && inputY == 0)
{
animator.SetBool("Walk", false);
}
else
{
animator.SetBool("Walk", true);
}
//Transform
if (inputX < 0)
{
spriteRenderer.flipX = true;
}
else
{
spriteRenderer.flipX = false;
}
_movement = new Vector3(inputX, 0, inputY).normalized;
}
private void FixedUpdate()
{
physicsBody.velocity= _movement * speed;
}
#endregion
}
}
Comment
Your answer
Follow this Question
Related Questions
How to fix this problem? 1 Answer
Ball Speed is not increasing as per code 0 Answers
Unity Annoyance with Physics Help C# Scripting Problem Momentum Issue Please Help 0 Answers
Problem. Pick up and Grab object script, except all objects in scene are picked up instead of one. 0 Answers
Ray cast to object to transform, instead all objects with script transform. 0 Answers