x


limit of speed for rigidbody

Hi guys I'm working on pinball game... here is the link link text (As you can see) I have problem with ball acceleration in this game. Is there any way to limit rigidbody acceleration with script? Regards.

more ▼

asked May 13 '12 at 08:38 PM

angelhard gravatar image

angelhard
27 2 2 5

Try

if (rigidbody.velocity.z > maxSpeed){ rigidbody.velocity.z = maxSpeed; }

May 13 '12 at 09:18 PM Pandiux
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can use Vector3.ClampMagnitude in FixedUpdate:

var maxVel: float = 10.0; // max absolute velocity

function FixedUpdate(){
  rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxVel);
}

ClampMagnitude doesn't modify the direction, just clamps its magnitude to the value passed.

more ▼

answered May 13 '12 at 09:27 PM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

Works perfect, thanks ;)

May 14 '12 at 11:38 AM angelhard

@angelhard, please click the check mark under the voting thumbs - this will help other users with similar problems, and - if rules didn't change - also adds 2 points to your reputation.

May 14 '12 at 11:42 AM aldonaletto
(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:

x1877
x97

asked: May 13 '12 at 08:38 PM

Seen: 624 times

Last Updated: May 14 '12 at 11:42 AM