x


how to jump with 2d?

i read tutorials and searched but nothing works. could someone tell me how make my character jump, please! Thanks!

Script:

var jumpSpeed = 8.0;

var gravity = 20.0;

private var moveDirection = Vector3.zero;

function FixedUpdate() {

var controller : CharacterController = GetComponent(CharacterController);

if (controller.isGrounded) { // We are grounded, so recalculate

// move direction directly from axes

moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,

Input.GetAxis("Vertical"));

moveDirection = transform.TransformDirection(moveDirection);

moveDirection *= speed;

if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } }

// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
controller.Move(moveDirection * Time.deltaTime);

}

more ▼

asked Aug 20 '10 at 01:12 AM

john 2 gravatar image

john 2
75 29 35 46

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

1 answer: sort voted first

Your question lacks detail. Right now there is nothing to do because I don't know how your script is made. Specificity is your friend, even more if you show that you're working hard and not waiting for someone to hand to you a ready to work code.

The 2D tutorial works. http://unity3d.com/support/resources/tutorials/2d-gameplay-tutorial

What I suggest is to open the tutorial's demo project and look at the character controller script. See how the jumping works(variables and functions) and try to add it to your own script. Once you've done that, if it still doesn't work, then show us a little of your script and enough detail so that we can help you find what is missing.

if you have a hard time understanding this, look for beginners's tutorials for scripting. They will greatly help, as well as the unity scripting reference.

I too am new to Unity and the first thing I do is to read all that I can see and find relevant. Look through the questions, there are surely a few talking about jumping. And also, it would help to look at how the questions are formulated. There are some questions that will never get an answer because of what I said above.

Good Luck

more ▼

answered Aug 20 '10 at 06:14 PM

Roux69 gravatar image

Roux69
22 1 1 5

I READ TUTORIALS as I SAID IN MY QUESTION BEFORE BUT IT JUST DOESN'T WORK. I ADDED MY SCRIPT!!!!!!!!

Aug 20 '10 at 06:28 PM john 2

First: please do not write in caps, it's very irritating. Second, I'm not home at the moment, I'll look into it tonight.

Aug 20 '10 at 06:37 PM Roux69

Whatever. i fixed it myself.

Aug 20 '10 at 10:02 PM john 2

Close your question then.

Feb 24 at 11:31 PM jbarba_ballytech
(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:

x5088
x3463
x3337
x336
x110

asked: Aug 20 '10 at 01:12 AM

Seen: 3149 times

Last Updated: Feb 24 at 11:31 PM