x


Setting Max Angular Force For Y For Jumping

As in my code I set my max force for left and right as 40, but when i set it to 600 for my jump, i can move unrelistically fast. Any way i can just set the max y instead of x an z?

more ▼

asked Apr 30 '12 at 03:08 AM

maroonrs2 gravatar image

maroonrs2
-55 8 12 13

I hate it when scripting pros are not on :)

Apr 30 '12 at 03:14 AM maroonrs2

What about adding constant force and manipulating that when needed?

Apr 30 '12 at 03:21 AM GC1983

more info please

Apr 30 '12 at 03:24 AM maroonrs2
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I don't know how you're using these max values - you should have posted your script.
Anyway, a good way to jump is to set the Y velocity directly - like this:

var jumpSpeed: float = 8.0;

function Update(){
  ...
  if (Input.GetButtonDown("Jump")){
    rigidbody.velocity.y = jumpSpeed;
  }
}

This code has a problem: you can jump even while in the middle of another jump. To avoid this, you can set a flag when starting a jump, and reset it when landing on the ground - but the ground or other objects where the rigidbody can land must have the same tag - Ground, for instance:

var jumpSpeed: float = 8.0;
private var jumping = false; // flag jumping

function Update(){
  ...
  if (!jumping && Input.GetButtonDown("Jump")){
    rigidbody.velocity.y = jumpSpeed;
    jumping = true;
  }
}

function OnCollisionEnter(col: Collision){
  if (col.gameObject.tag == "Ground"){
    jumping = false; // reset the flag when landing on some Ground object
  }
}
more ▼

answered Apr 30 '12 at 04:40 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

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

need the script, not quite sure what you mean.. If you're using a character controller, you can use something like this:

http://unity3d.com/support/documentation/ScriptReference/CharacterController.Move.html

similar to above, one note: uses controller.isGrounded to automatically check for being grounded

not sure if your issue is one of move speed, or rotation. post the script if you could

more ▼

answered Apr 30 '12 at 04:47 AM

Seth Bergman gravatar image

Seth Bergman
7k 10 16 28

I do not recomend using tag, but CompareTag as tag will malfunction.

May 01 '12 at 04:11 PM maroonrs2
(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:

x1793
x318
x292
x15

asked: Apr 30 '12 at 03:08 AM

Seen: 500 times

Last Updated: May 01 '12 at 04:11 PM