Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

Unwanted Movement - Damping not working?  [SOLVED]

All about the StoneScript

Unwanted Movement - Damping not working?

Postby Badger » 17 Jun 2012, 08:03

Hi all, noob here, possibly silly question, can't work it out. Searched all over...

Short version: Have a dynamics controller. Only applying force along Z axis. Using setLinearDampingEx with very high values on X axis. Object still moves along X axis somehow, following "tri" on basic geometry from Blender or created directly in Shiva.

I'm using the AI model from boxman with some modifications. Here's the code from the updateDynamics function:

Code: Select all
dynamics.setLinearDampingEx ( hDynObj, 1000, 0, 1 )

local Zx, Zy, Zz = object.getDirection ( hDynObj, object.kGlobalSpace )       
Zx, Zy, Zz = math.vectorScale ( Zx, Zy, Zz, nnSpeed * 200 )
       
local fx, fy, fz = math.vectorAdd ( 0, 0, 0, 0, 0, Zz )

dynamics.addForce ( hDynObj, 0, 0, fz, object.kGlobalSpace )
dynamics.addForce ( hDynObj, 0, this.nGravity ( ), 0, object.kGlobalSpace )
     
object.matchTranslation ( hObject, hDynObj, object.kGlobalSpace )


Note direction of hDynObj is continually 0, 0, -1

Screenshots showing the problem in action below. The ground collider is an extruded cube mesh from blender (flat), exported and passed through ultimate unwrap. Once the dynamic object hits an edge it begins to "follow" it only using the code as above. Same thing happens with a Shiva created box.

The distance travelled along X is dependant on the speed of the object. If I increase the speed, the object passes the edge more quickly, but is still affected by it.

I can bork it and translate the dynamic to X 0, but that doesn't really solve the problem. Any ideas? Sorry if I'm missing something glaringly obvious. Thanks for looking.

Begin moving along Z, X starts at 0:
Image

Continue moving along Z, X increases:
Image
________________________________
˙ןǝnuɐɯɯǝ osןɐ ɯ,ı
User avatar
Badger
Gold Boarder
Gold Boarder
 
Posts: 180
Location: Australia

Re: Unwanted Movement - Damping not working?

Postby shivachristy » 17 Jun 2012, 11:21

Have you tried changing the mass of the object to see what affect that has

Someone said to me dont get too hung up on the mass values but get the effect you want by messing around with all teh paramaters.

You could also set the object to idle if the movement is below a certain value.
http://cur.lv/1x0wx via an ad! Thanks
User avatar
shivachristy
Platinum Boarder
Platinum Boarder
 
Posts: 1036
Location: UK

Re: Unwanted Movement - Damping not working?

Postby Badger » 17 Jun 2012, 12:05

shivachristy wrote:Have you tried changing the mass of the object to see what affect that has

Someone said to me dont get too hung up on the mass values but get the effect you want by messing around with all teh paramaters.

You could also set the object to idle if the movement is below a certain value.


Thanks for the reply. I've been fiddling with everything, no luck. I thought I had more of a reply, then I went back and examined the sample some more. I think I'll screw around with it in the morning, create the dynamic controller in the scene instead of at runtime, see what I can do.

Cheers.
________________________________
˙ןǝnuɐɯɯǝ osןɐ ɯ,ı
User avatar
Badger
Gold Boarder
Gold Boarder
 
Posts: 180
Location: Australia

Re: Unwanted Movement - Damping not working?

Postby broozar » 17 Jun 2012, 19:59

basicly what youare saying is, the ball moves along X and Z, although you only apply a force to X and Y?

i would suggest 3 things,
a) test without your gravity function
b) apply angular damping for the axis you do not want the ball to rotate on
c) don't use getDirection, it returns the normalized -z axis vector, and if there's a slight error, it will haunt you.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3564
Location: Berlin - Germany

Re: Unwanted Movement - Damping not working?

Postby dbladez » 17 Jun 2012, 20:44

Could try out.

dynamics.setLinearDampingEx ( hDynObj, math.kInfinity, 0, 1 )
or
dynamics.setAngularDamping ( hObject, math.kInfinity, 0, 0 )

Even with that. I've found that sometimes my object still will move on an unwanted axis just a bit by .001 over time.
So each frame I just get the objects translations.

local X, Y, Z = object.getTranslation ( this.getObject ( ) , object.kGlobalSpace )
then
object.setTranslation ( this.getObject ( ) , 0, Y, Z, object.kGlobalSpace )

Essentially resetting X to 0 or whatever you wish.
User avatar
dbladez
Platinum Boarder
Platinum Boarder
 
Posts: 682
Location: Ontario, Canada

Re: Unwanted Movement - Damping not working?

Postby Badger » 18 Jun 2012, 00:43

Thanks so much for the replies. No real resolution for why this is happening or but I have a usable workaround at this point.

broozar wrote:basicly what youare saying is, the ball moves along X and Z, although you only apply a force to X and Y?

i would suggest 3 things,
a) test without your gravity function
b) apply angular damping for the axis you do not want the ball to rotate on
c) don't use getDirection, it returns the normalized -z axis vector, and if there's a slight error, it will haunt you.


The ball (static model attached to spherical dynamic controller) moves along Z and X when I only apply force to Z.

a) Commenting out the gravity line shows a huge change, the object no longer appears to "stick" to those edges; however the object still moves along the X axis with no force applied in that direction (extremely miniscule amounts but will still add up over time).

b) angular damping still seems to allow tiny movements on the unwanted axis

c) I changed my code to the below and the result is the same. (Forgive me for my poor understanding of what I'm doing at this point).
Code: Select all
local Zx, Zy, Zz = object.getZAxis ( hDynObj, object.kGlobalSpace )
Zx, Zy, Zz = math.vectorScale ( 0, 0, -Zz, nnSpeed * 200 )




dbladez wrote:Could try out.

dynamics.setLinearDampingEx ( hDynObj, math.kInfinity, 0, 1 )
or
dynamics.setAngularDamping ( hObject, math.kInfinity, 0, 0 )

Even with that. I've found that sometimes my object still will move on an unwanted axis just a bit by .001 over time.
So each frame I just get the objects translations.

local X, Y, Z = object.getTranslation ( this.getObject ( ) , object.kGlobalSpace )
then
object.setTranslation ( this.getObject ( ) , 0, Y, Z, object.kGlobalSpace )

Essentially resetting X to 0 or whatever you wish.


I attempted using kInfinity on damping functions however as you say, for some reason it still allows some movement.

Your solution to reset the desired axis is more or less what I was doing to force a constant value along the X axis. I wasn't keen on going with something like this as I've been thinking that if I'm going to use dynamics for object movement I should force them into the desired position within the confines of the existing physics system instead of manual translations.

So, silly me, I've overlooked the guard box. It's working for me. I don't have a resolution for the unwanted movement, but I do have a workaround to force my objects X movement to stay almost exactly where I want it while still using dynamics functions.

Thanks all for your help. I'm not sure if I should mark this as solved.

Cheers.
________________________________
˙ןǝnuɐɯɯǝ osןɐ ɯ,ı
User avatar
Badger
Gold Boarder
Gold Boarder
 
Posts: 180
Location: Australia

Re: Unwanted Movement - Damping not working?

Postby TRANE23 » 21 Jun 2012, 17:15

All is normal. You apply a force on a spherical object which collides on a plane and which is rotating so ODE may computes some very little X moves even if there is a damping. The equation contains a lot of variables and in your case it is not Force on Z Axis -> Move on Z Axis . You can use the guardbox as you did and/or remove physics rotation and/or use Cube Body.
:D
TRANE23
Senior Boarder
Senior Boarder
 
Posts: 53
Location: France

Re: Unwanted Movement - Damping not working?  [SOLVED]

Postby Badger » 30 Jun 2012, 07:59

Thanks again for the replies. Guard box is working well. I guess the logic my brain was after could be summed up as "it's a dynamics system attempting to simulate real movement"(?) So small nudges along axes are normal.

TRANE23 wrote:All is normal. You apply a force on a spherical object which collides on a plane and which is rotating so ODE may computes some very little X moves even if there is a damping. The equation contains a lot of variables and in your case it is not Force on Z Axis -> Move on Z Axis . You can use the guardbox as you did and/or remove physics rotation and/or use Cube Body.
:D


How would you "remove physics rotation" in script when using a sphere body? Just use setRotation? And would this affect linear movement of the sphere body? Could experiment i suppose...

Cheers.
________________________________
˙ןǝnuɐɯɯǝ osןɐ ɯ,ı
User avatar
Badger
Gold Boarder
Gold Boarder
 
Posts: 180
Location: Australia

Re: Unwanted Movement - Damping not working?

Postby TRANE23 » 13 Jul 2012, 20:46

Yes with script : dynamics.enableRotations ( hObject, bEnable ) :D
TRANE23
Senior Boarder
Senior Boarder
 
Posts: 53
Location: France


Return to Game programming