- Home /
i have the code to move my rigid body upward.
my code lets me move my rigid body move upward. it just jump in fixed position. but i want my rigid body to jump upward as well as move forward. how can i achieve. i tried addforce but nothing worked
if (isGrounded) { moveVector = transform.forward * jumpForwardheight; if (jump) { anim.SetBool("IsJump", true); Vector3 temp2 = rb.velocity; temp2.y = jumpHeight; rb.velocity = temp2; } if (!jump) { anim.SetBool("IsJump", false); } }
Answer by Santosh_Nair · Oct 14, 2018 at 06:50 AM
You can use the following for addforce.
GetComponent ().AddForce ((transform.right moveForce) + (transform.up jumpForce));
Here, moveforce is float value of how much displacement you towards towards right and jumpforce is a float value that determines how high your player jump. So in a way it will create an arc by totaling both forces along X and Y axis.
Edit 1: In the answer, transform.right is multiplied by moveforce and same for jumpforce. However, the "*" in between is not shown after submitting the reply.
it did not work brother. may be both force are being cancel. is there any other way.
Hey, I have made an edit in the answer,after finding the multiplication missing. Could you check for that?
thanks a lot for help :) but i tried different method and it worked.
Your answer
![](https://koobas.hobune.stream/wayback/20220612180307im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Keep Horizontal Momentum after Jump 2 Answers
How do I make my character jump? 1 Answer
Simple AddForce Scirpt help 1 Answer