x


How to constraint the motion of a rigid body to the xz plane?

Hi Guys,

I am working on a game similar to air hockey. I want to restrict the movement of puck to xz axis. Currently when i hit the puck it travels in y axis with some units too. but i dont want it to leave the base ever. plz help..................

more ▼

asked Jan 06 '11 at 09:41 AM

user-8010 (google) gravatar image

user-8010 (google)
1 3 3 6

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

3 answers: sort voted first

you could use Rigidbody.constraints if you are using a rigidbody... Unity could not find RigidbodyConstraints when i tried it even though its there on unity site. Maybe you will have better luck in findng out how to use it. If you do use it, do share... you could use: rigidbody.constraints = RigidbodyConstraints.FreezePositionY;

Source: http://unity3d.com/support/documentation/ScriptReference/Rigidbody-constraints.html

more ▼

answered Feb 26 '11 at 07:20 AM

Antzy gravatar image

Antzy
11 1

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

You could add the following to the Update function in the script attached to your puck: transform.position.y = 0;

more ▼

answered Jan 06 '11 at 11:00 AM

cjmarsh gravatar image

cjmarsh
373 2 9

Hi,

Thnx fr the reply... but it still moves a bit in y position... Actually I have 2 pucks.. I hit 1 puck with other using power. But in some cases, what happens is puck 1 goes over the puck 2.... ? What to do plz help bro

Jan 06 '11 at 11:11 AM user-8010 (google)

When you say 'goes over' do you mean it goes up and over or it just goes 'through' the other puck?

Jan 06 '11 at 11:30 AM Meltdown

It goes up and over, not thru...

Jan 06 '11 at 11:42 AM user-8010 (google)

You could try Rigidbody.useGravity = false; on each puck. This should get rid of the force being applied to them in the y direction.

Jan 06 '11 at 11:45 AM cjmarsh

did that but no use... Its happening at random. Sometimes the puck travels in y and sometimes it doesnt...plz help

Jan 07 '11 at 05:34 AM user-8010 (google)
(comments are locked)
10|3000 characters needed characters left

the "dirty" update version works, but did anybody figure out how these constraints actually work?

more ▼

answered Oct 24 '11 at 05:21 PM

Somian gravatar image

Somian
206 35 46 52

(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:

x322
x134
x32

asked: Jan 06 '11 at 09:41 AM

Seen: 2446 times

Last Updated: Feb 08 '12 at 02:01 PM