Restrict angle of rotation on one axis.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
nizgtr
Posts: 6
Joined: Mon May 30, 2011 2:44 am

Restrict angle of rotation on one axis.

Post by nizgtr »

Hi, first off an amazing physics engine! Great job.

I have a space ship on screen that is a dynamic entity and i want it to gradually lean into the direction the user presses but only a max of 25 degrees, for example in either direction, on the Z axis. How can this be achieved in BEPU?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Restrict angle of rotation on one axis.

Post by Norbo »

For the maximum angle in isolation, RevoluteLimits would do the job. They're a two entity constraint, but you can pass null in for one of the connections and it will behave as though it's connected to the world.

For the "gradually lean" part, you'd have to work out the exact nature of the behavior first. If, at any point during a turn, you know exactly the angle at which you want the object to lean, then you could use a RevoluteMotor (which is also a two entity constraint). If you're using a RevoluteMotor which directly specifies the angle, you probably wouldn't need to also use a RevoluteLimit.

Also, note that constraints are generally valuable for adding stability in complex multibody structures. When dealing with single entities in isolation- like a spaceship floating around- just setting the velocities directly will generally work just fine. Or, if you'd prefer to work on the position/orientation level, you could use an EntityMover/EntityRotator to translate the goal state into velocities. In the event that you don't care much about collision response, you could also just directly set the Position and Orientation directly.
nizgtr
Posts: 6
Joined: Mon May 30, 2011 2:44 am

Re: Restrict angle of rotation on one axis.

Post by nizgtr »

I see, EntityRotator sounds like what i need.

The thing about setting the Orientation directly is that theres no reliable way to get the current degree of the angle from a Quaternion or Matrix.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Restrict angle of rotation on one axis.

Post by Norbo »

The thing about setting the Orientation directly is that theres no reliable way to get the current degree of the angle.
There is; you would just have to consistently choose the frame of reference with which the measurement is performed. That's what the RevoluteLimit and RevoluteMotor (in servo mode) do internally.

Note that the EntityRotator just takes an orientation. If the EntityRotator can work, then setting the Orientation directly can work too (provided that you're okay with the side effects with regards to collision response).
Post Reply