Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Getting Started

Completely reset dynamics

You feel lost? You don't understand how to use ShiVa?

Completely reset dynamics

Postby TailsetSonic » 16 Jun 2012, 11:26

Hello,

I'm implementing a specific action when my character is jumping. While jumping, when I push the jump button in the airs, my character dash on the closer targeted ennemy. For that, I set the linear velocity of my character to 0, I disable the gravity and then I add a linear inpulse. Logicaly my character's trajectory must be a line but it isn't. I think there still is inertia force or something like that. Is there any solution to completely reset all the forces on the object ?
TailsetSonic
Senior Boarder
Senior Boarder
 
Posts: 41

Re: Completely reset dynamics

Postby broozar » 16 Jun 2012, 11:38

have you tried setting it into a kinematic state? then wait a frame (sendevent), then set kinematic to false again.

http://www.stonetrip.com/developer/doc/api/dynamics-setKinematic

PS: for a full stop after a jump, i usually just do a velocity=0 call.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3512
Location: Berlin - Germany

Re: Completely reset dynamics

Postby TailsetSonic » 17 Jun 2012, 05:44

Ok I'll try with that. But if velocity=0 stops my object, why my trajectory, after a linear impulse, is not rectilinear ? =/

After test : The result if better but someone it still has the same problem

particularly in this case :

OnEnterState :
Code: Select all
local tX, tY, tZ = object.getTranslation ( this.getObject ( ), object.kGlobalSpace )
local aX, aY, aZ = object.getXAxis ( this.getObject ( ), object.kGlobalSpace )

this.nTargetX ( tX + aX * 14 )
this.nTargetY ( tY - 1 )
this.nTargetZ ( tZ + aZ * 14 )

dynamics.enableGravity ( this.hDyn ( ), false )
   
local vX = this.nTargetX ( ) - tX
local vY = this.nTargetY ( ) - tY
local vZ = this.nTargetZ ( ) - tZ
dynamics.setKinematic ( this.hDyn ( ), true )
dynamics.setLinearVelocity ( this.hDyn ( ), vX * 25, vY *25, vZ *25, object.kGlobalSpace )


OnLoop :
Code: Select all
local tX, tY, tZ = object.getTranslation ( this.getObject ( ), object.kGlobalSpace )
local dX = this.nTargetX ( )
local dY = this.nTargetY ( )
local dZ = this.nTargetZ ( )

local object_dist = math.sqrt ( math.pow ( dX - tX, 2 ) + math.pow ( dY - tY, 2 ) + math.pow ( dZ - tZ, 2 ) )
   
log.message ( "Dist : ", object_dist ) 
if ( object_dist < 1.3 )
then
    this.InTheAirs ( ) -- state change
end


And finally sometime I get that :

[o Message ] {Scripting }Dist : 8.54269
[o Message ] {Scripting }Dist : 3.54424
[o Message ] {Scripting }Dist : 2.22447
[o Message ] {Scripting }Dist : 4.93043
[o Message ] {Scripting }Dist : 9.88928
[...]
TailsetSonic
Senior Boarder
Senior Boarder
 
Posts: 41

Re: Completely reset dynamics

Postby TailsetSonic » 29 Jun 2012, 10:57

Hello,

I still have the same problem.
I don't understand ... It seems to have a little force that push it up or down (it depends). Is it a bug ? Because of that my character sometime miss the targeted point and so continues his trajectory. He slow down to stop (because of the air resistance ?) and then he goes continuously and slowly up or down
TailsetSonic
Senior Boarder
Senior Boarder
 
Posts: 41

Re: Completely reset dynamics

Postby DoctorPepper » 29 Jun 2012, 12:36

A lot of weird stuff going on in ur code. for instance you are setting Vx to
(( tX + aX * 14 ) - tX )*25 . That looks rlly strange.

Wouldnt it be easier to get a directional vector, set velocity to 0 and add an impulse from there. Also dont forget to disable rotation, or it will mess up everything

so, if A (x,y,z) is position of the character and B (v,w,p) is translation of the target.
Then directional vector N is (v-x,w-y,p-z). If C is some constant, probably a few k.

dynamics.setLinearVelocity ( ... 0,0,0 ... )
dynamics.enableGravity ( ... false )
dynamics.addLinearImpulse ( ... N * C ... )

All there is to it. Or am i missing something?
User avatar
DoctorPepper
Platinum Boarder
Platinum Boarder
 
Posts: 474
Location: Belgium

Re: Completely reset dynamics

Postby TailsetSonic » 30 Jun 2012, 14:44

That's exactly what I make. Maybe it's the rotation so. I changed the way I do that anyway. If I still have this problem at a moment, disabling the rotation, i'll tell you.

Thanks
TailsetSonic
Senior Boarder
Senior Boarder
 
Posts: 41

Re: Completely reset dynamics

Postby DoctorPepper » 30 Jun 2012, 16:02

Its nothing like what i said.

You never set the speed to 0 in the code you posted
You never get targets coordinates
You never actually add linear impuls (force) dynamics.addLinearImpulse (
You are using a directional vector asif its a velocity vector, disregarding the fact that v=dr/dt
Calculation for custom velocity (which you shouldnt be doing) doesnt make any sense.

So in a way, what i wrote is exactly what you didnt do
User avatar
DoctorPepper
Platinum Boarder
Platinum Boarder
 
Posts: 474
Location: Belgium

Re: Completely reset dynamics

Postby TailsetSonic » 05 Jul 2012, 10:53

I don't really understand the problem, that doesn't explains why this happened.
TailsetSonic
Senior Boarder
Senior Boarder
 
Posts: 41


Return to Getting Started