hello.
how to make an object jump in the direction it is looking? I’m trying to implement a frog jump.
if (Input.GetKey(KeyCode.Space) && jumpForce <= 5)
{
jumpForce += 1 * Time.deltaTime;
}
if (Input.GetKeyUp(KeyCode.Space) && isGrounded)
{
isGrounded = false;
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
jumpForce = 2f;
}
The above could do that, with a charge-up the longer you hold it. Is it working? What is the value of jump
?
depends a little on the value of jump there I guess, but, transform.forward is the way its facing, now, if its looking sideways then you clearly need to adjust, but if you have a thing and its facing the way its looking. transform.forward takes you in that direction just like normal movement
You need to make your jump vector point in the direction that the frog is looking. You probably want to combine a straight up vector Vector3.up
with the frog’s transform.forward
vector.
Yes, it works. Jump is just a variable, the force of the jump.