- Home /
Question by
CForCasual · Mar 30, 2018 at 02:02 PM ·
movementrigidbody2dvelocityvector2fixedupdate
Character won't move (Fixed)
I was making a game, and I encountered this problem. The character wouldn't move. This code used to always work but this time, it gives me this error message:
NullReferenceException: Object reference not set to an instance of an object PlayerOneScript1.Movement (Single moveHorizontal) (at Assets/Scripts/PlayerOneScript1.cs:159) PlayerOneScript1.FixedUpdate () (at Assets/Scripts/PlayerOneScript1.cs:155)
Here is the code I wrote:
public void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
Movement(moveHorizontal);
}
private void Movement(float moveHorizontal)
{
rB.velocity = new Vector2(moveHorizontal * playerSpeed, rB.velocity.y);
}
The first line of code is the 152th line. The character won't move or jump or anything! Help!
Comment
Best Answer
Answer by Skyunarankage · Mar 30, 2018 at 02:08 PM
did you attach the correct rB?
O$$anonymous$$G I didn't assign the Rigid body variable. Problem fixed thx so much