I am making a parkour/puzzle game and my player is a simple cube.
I have movement down, but what I can’t figure out is how to make my cube jump. I have used many different tutorials, but the best one i can find allows my player to jump onto the side of a wall and continue to walk around the wall. That defeats the purpose of the locked door.
Can someone please help me?
It is a 3d game and I am using version #Unity-5-3.5 Personal Edition
I’m a newbie too but we’ll learn together.
Writing your own script for movement basically involves attaching the script to the gameobject, and having the script say “If the player presses the spacebar, add an upwards force to the gameobject’s rigidbody.” Then the player would get a height boost accordingly, and the game’s physics engine might bring them back down with gravity? Like I said I’m new too but here’s about what I would start with
public float jumpheight;
private RigidBody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate{
if(Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector3(0, 10 * jumpheight * Time.deltaTime, 0);
}
I’m hoping someone will correct me, I’m eager to know also.
There’s some other thing about using OnCollisionStay to detect whether they were on a solid surface before they jumped. Sounds useful.
I’ve also seen something about, using the navmesh to define where your character can navigate, where it can define (and you can too with pro) places the player can jump to/from.
You could do everything that you are doing but also add a gravity modifier variable,
public float gravityModifier;
add it to your physics (like in real life how you have gravity),
Physics.gravity *= gravityModifier;
and add something to immediately apply those forces,
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
Now Im still learning too, and ill try to help unless youve fixed it but also future references.