Is it Gravity or something?

In the FAQ about setting up a first-person walkthrough they never mention doing anything fancy. I tried it, and have a problem.

  1. I dropeed a mesh onto the scene.

  2. I dropped a first person camera, and aimed it at the mesh.

  3. Clicked “Game” to run it, and I see the mesh moved away further and further…until it is gone!

I’m stumped.

Can someone help this noob? Thanks!

The default first person controller is set up with basic gravity, yes, so if your scene doesn’t have any terrain or colliders under the controller the camera will just fall down, and down, and down…

The gravity is part of the FPS Controller script and only affects the controller. The mesh doesn’t have any scripts attached, so it won’t do anything, not even fall. So what you’re seeing is the mesh staying put while the controller (and attached camera) falls down into empty space, so you need to put something with a collider under the controller as a floor, like a plane with a mesh collider or terrain.

dawvee,

Thanks very much!

My game is sort of a space game. There is no “floor”.

Would it work to simple parent the first person controller to another, gravity-less object?

Nope. The script makes it fall whether it has a parent or not.

What you need to do is create your own controller script that’s more focused towards whatever the character is.

Gargerath,

Thanks!

Gargerath is right, that at this point you’ll need to do some scripting. The best thing would probably be to look at the FPSWalker script you’re using now to see what it’s doing.

You can probably adjust the existing script to suit your needs if you want, too. There’s just one line that handles the gravity calculation, for example, and it’s even commented as such:

// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

If you take that out, you’ll have a character controller that will move around on an invisible plane and fly upwards when you press jump (but won’t fall back down), so you’ll need to figure out how to create movement that makes sense in full three dimensions, but understanding the existing movement script is a great place to start. Have fun!

Dawvee,

That is very helpful to me.

Thanks you very much!