Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

Hinge2 motor  [SOLVED]

All about the StoneScript

Hinge2 motor

Postby liechten » 17 May 2012, 13:21

Hi,

I'm trying to make a model that has a hinge2 joint and I want it to be able to rotate in both directions in runtime.
After the start of the application I don't want the motor rotating, so I'm setting the Axis2 direction and "0" as acceleration parameter:

Code: Select all
dynamics.setHinge2JointAxis2 ( this.hMotor(), 'hj', 0, 0, 1, object.kGlobalSpace )
dynamics.setHinge2JointAxis2MotorAcceleration ( this.hMotor(), 'hj', 0)


And then, during the game I would like the motor to rotate in one or another direction after I press some key. So, in the onKeyboardKeyDown handler I have the following:

Code: Select all
   
if(kKeyCode == input.kKeyLeft)
    then
        log.message ( 'rotate left' )
        dynamics.setHinge2JointAxis2 ( this.hMotor ( ), 'hj', 0, 0, 1, object.kGlobalSpace )
        dynamics.setHinge2JointAxis2MotorAcceleration ( this.hMotor(), 'hj', 100000)

    elseif(kKeyCode == input.kKeyRight)
    then
        log.message ( 'rotate right' )
        dynamics.setHinge2JointAxis2 ( this.hMotor ( ), 'hj', 0, 0, -1, object.kGlobalSpace )
        dynamics.setHinge2JointAxis2MotorAcceleration ( this.hMotor(), 'hj', 100000)


To change the direction of rotation I'm setting Axis2 to the opposite direction.
But this does not work the way I want.
After the start of the game it the model moves a bit (some very very small movement, but it is noticeable), although no forces are applied to the model yet.
And when I press kKeyLeft - the model does not react. But when I press kKeyRight - it starts rotating, and do not stop after that.

Please, advise on the using of hinge2 motor feature. Because I could not find any good documentation about it.
If you can post link to some sample code, or an article, describing this - it would be greatly appreciated.

Thanks!
Artem
liechten
Fresh Boarder
Fresh Boarder
 
Posts: 11

Re: Hinge2 motor  [SOLVED]

Postby broozar » 17 May 2012, 15:26

hello artem,

i am not sure if you have seen the documentation example here, so i'll just post it again http://www.stonetrip.com/developer/doc/api/dynamics-createHinge2Joint
dynamics.setHinge2JointAxis2MotorAcceleration is a setup parameter that goes into an init script, not something you want to change on a keypress.

to get a better understanding of hinge2 joints, you should know that shiva uses the ODE physics engine and derives most of those physics functions directly from there. here's the hinge-2 doc for ODE: http://www.ode.org/ode-latest-userguide.html#sec_7_3_5 changing axis on the fly is probably not what you want to do.

Hinges exist between 2 physics objects. to rotate one around the other, apply a force to one of them after you have "jointed" them together, for example using angular velocity http://www.stonetrip.com/developer/doc/api/dynamics-setAngularVelocity or torque http://www.stonetrip.com/developer/doc/api/dynamics-addTorque. those are the functions you want to call on keypress. it is also advisable to just send events with keypresses and not controlling the object in the keypress handler itself.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3347
Location: Berlin - Germany

Re: Hinge2 motor

Postby liechten » 17 May 2012, 16:43

Thank you for suggestion.
liechten
Fresh Boarder
Fresh Boarder
 
Posts: 11


Return to Game programming