Player movement ; Not moving

Console shows no error. But it’s not doing what I want. I want the player to move forward when the forward key is pressed. (W) When W is pressed, the walk animation plays but the player does not move forward. View the FixedUpdate() to see what I did for movement.

using UnityEngine;
using System.Collections;

public class Moving : MonoBehaviour {
//Animation Var
private Animator anim;
private float vert;
//Movement Var
public float speed;
public Rigidbody playerRigidBody;

// Use this for initialization
void Start () {
anim = GetComponent();
}

// Update is called once per frame
void Update () {
vert = Input.GetAxis (“Vertical”);
anim.SetFloat (“walk”, vert);
}

//Updates before physics right?
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis (“Horizontal”); //Pressed W?
float moveVertical = Input.GetAxis (“Vertical”); //Pressed A or D?

Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); //What is 0.0f?

if( movement != Vector3.zero) {
GetComponent().AddForce(movement * speed * Time.deltaTime);
}
}
}

It’s possible you’re just not applying enough force (what is speed set to?) because you’re scaling it by delta time, which you don’t need to do for physics based movement. Check out the docs.

You also shouldn’t be polling input in FixedUpdate() but storing the value from Update() and using that in your FixedUpdate() calls.

2206654--146638--660079.png

1 Like

I couldn’t figure out how to change the image. I’m sorry if it offends you.

I didn’t have enough force. I changed it to 20,000. But, the payer falls over now. Although it moves forward now. Is there a way I can make the player stay up?

You can freeze the rotation by checking the boxes on the rigidbody:

If you’re trying to move a character though, like Doomguy or Mario or whatever, you’re probably better off using a character controller instead of manipulating forces.

This is hysterical.

You and your pic are completely bawdy, yet you’re here asking for help.

Good luck with that.

It didn’t offend me but I thought I would show you the impression your avatar gave people when you were asking for help :wink: personally I thought it was funny. But it’s probably not the best avatar to ask for help with!

Changing it was probably a good idea.