Forced movement when climbing and jumping(leap)

Hi, I have this mouse and I want him to be able to climb stuff and when I press jump, he should make an upward leap, how do I do this? I tried freezing rotation so he should stick to the wall if nothing is pressed, and managed to detach from it and make him jump, but i want a leap not a jump, should be something like this

If you have any ideeas please feel free to comment it down below thanks!! :smile: sorry for bad english

Find the center point of starting to finished position then use radians to plot the circular path that you want.

1 Like

sorry , Im a bit new to Unity how do I plot the radians circular path ?

Not a Unity thing and kind of complicated so I can’t really write it for you here. Otherwise if using physics just cheat it with a force to the left then a force to the right when passing your center point.

I tried exactly that but i dont know why it doesnt work…

Attach a code snippet of just jumping up the wall and any explanation or video of what it currently does and I’ll try to help.

1 Like

Sure here is the code :

public void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == “Wall”)
{
myRigidBody.constraints = RigidbodyConstraints2D.FreezeAll;
}
}

public void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.tag == “Wall” && myRigidBody.velocity.y <= 0.5f)
{
myRigidBody.constraints = RigidbodyConstraints2D.FreezeAll;
}

if (collision.gameObject.tag == “Wall” && Input.GetKeyDown(KeyCode.Space))
{
myRigidBody.constraints = RigidbodyConstraints2D.None;
myRigidBody.constraints = RigidbodyConstraints2D.FreezeRotation;
myRigidBody.velocity = Vector2.up * JumpForce;
}
}

And a video :

Remember that when your mouse is on the wall the global “up” vector is not what you want to use. You want to use the mouses local up vector.

So the mouses up vector is what should be getting the jump force. Your going to want to do your gravity manually as well.

If it were me, I would probably use an animation curve to control the height and distance of the mouses jump. When sticking to a wall I would disable gravity, and apply my own fake gravity to stick the mouse to the the wall. Then when my mouse jumps on the wall, I would toggle my fake gravity off and sample the position along the animation curve to get the mouses desired position.

Video doesn’t work for me. I’m going to assume your character goes straight up the amount of distance you want.
And I don’t use the physics system often so may not know fully some specifics.

You have myRigidBody.velocity = Vector2.up * JumpForce;
You need to find the final point that would lead to if gravity and friction from the wall is constant. Let’s say the distance you will travel is y(y is assuming a positive number that represents units traveled above the player).

y *= 0.5f; to find our middle point.

y += player.transform.position.y; to find our middle point relative to our player.

So your going to need to manually add velocity with a new Vector3(x,y,z) instead of Vector.up or maybe you can do one left as well not sure how it works. Or AddForce up and Addforce left instead.

After our player is greater or equal to y send the player back to the wall.

Thata pretty interesting for me to do… i will check it thanks a lot for the ideea ! <3

now THAT I think will do, create an animation ! Thank you sir!