x


how do i make my character jump without using character controller

i have a character moving on a plane at a constant speed it has a rigidbody and a box collider i have written code to make it jump,but when i hit spacebar it just floats in the air and den drops(not cool at all).I want it to make a jump like the one in temple run but don't know how.Please help.This is my current code.

//controls fish jumping
if (isMoving&&Input.GetButtonDown("Jump")){
transform.Translate(Vector3.up*4);
}
more ▼

asked Oct 09, 2013 at 11:55 AM

el-santia93 gravatar image

el-santia93
121 18 27 73

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

NOT TESTED, but try using the rigidbody.AddForce methods.

//controls fish jumping
    if (isMoving&&Input.GetButtonDown("Jump")){
    rigidbody.AddForce(Vector3.up * 4);
}

rigidbody.AddForce()

more ▼

answered Oct 09, 2013 at 12:25 PM

verenion gravatar image

verenion
293 6 8 10

thanls for the reply will try it out

Oct 09, 2013 at 12:40 PM el-santia93

This will however, apply the force everytime the Jump button is pressed, leading to the player being able to jump as high as they link by spamming the button. You would have to introduce some sort of ground check to see if the player is grounded before jumping.

Oct 09, 2013 at 12:42 PM verenion

still didnt work since i am using gravity to bring the character down is there anyway i can tweak the gravity to bring it down faster?

Oct 09, 2013 at 12:52 PM el-santia93

Edit->Project Settings->Physics.

You can adjust the vector of the gravity. -9.81 means that the force on the object will be -9.81 on y axis (I.e DOWN). You could adjust that, or you could adjust the upwards force of your jump.

// multiplying a vector by a scalar (E.g. 50) will increase it's magnitude.
rigidbody.AddForce(Vector3.up * 50);
Oct 09, 2013 at 12:56 PM verenion

If this helped/ solved your issue, please vote and select as an answer, and close the question.

Oct 14, 2013 at 09:41 AM verenion
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x331
x219

asked: Oct 09, 2013 at 11:55 AM

Seen: 929 times

Last Updated: Oct 14, 2013 at 09:41 AM