[SOLVED] Constant movement that obeys physics

So I’m making a first person game for the google cardboard VR headset, and it needs to be hands free. The direction the player is looking in is easily controlled with downloadable variations on Mouselook, but I need the player to be moving forward on their own. I tried the rigidbody constantforce option, but the player then passes through colliders, and turning on gravity makes them fall through the map. The three things I need are:
a) Constant forwards movement
b) Actual working collisions
c) Obeying gravity

Essentially the equivalent of holding “w” all the time with the FPS Input controller.
Thanks!

Shooting from the hip I’m guessing you need to handle the side to side rotation in the rigid body and the up and down in the camera. Parent them both to an empty. Then simply do a transform translate in the fixed update in a forward direction on the rigid body.

You are flying through the ground and up because the rigid body is changing the up and down rotation which points forward up or down.

Makes sense. I’ll check when I get back to my computer.

EDIT:
Yeah okay so I know what I need to do in theory: Limit the x axis rotation for the rigid body, and then apply a constant force to it, while the camera takes care of the vertical.
So would

function Update () {
    rigidbody.constraints=RigidbodyConstraints.FreezeRotationX;
}

be okay?

If you’re falling through the map, I’m guessing your character and/or terrain don’t have colliders? I don’t know what you’ve got going on, but what you want should be just a simple matter of using Unity’s built in physics and setting the player’s/camera’s rotation and forward velocity.

You probably also want to use FixedUpdate.

1 Like

You don’t even need code for that. If you expand the rigid body tab there is a box you can click to stop rotation on the axis.

For some reason I had forgotten to give my camera a collider. Thanks for the reminder. That solves the through the floor thing. I feel incredibly dumb right now.

I know about the check boxes, but for some reason when I check the X Axis constraint box and hit play, Unity thinks it’s funny to tick all three of them.

EDIT: Okay I’ve got it sorted. Just added a capsule collider, gave the camera a rigid body, turned gravity ON. Then wondered why it wasn’t moving, so I went to eat some food, then came back and cranked up the constant force on the rigid body, and voila! Thanks for all your help.