Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

Dynamic Collision Problem  [SOLVED]

All about the StoneScript

Dynamic Collision Problem

Postby MrGamer » 21 Jun 2012, 11:12

My player has a dynamic object attached scaled to 0.1 and when moving at velocity of 18 it sometimes passes through walls and floors with collider enabled. This should not be possible. Looking for solution.
MrGamer
Expert Boarder
Expert Boarder
 
Posts: 137

Re: Dynamic Collision Problem

Postby neilb » 21 Jun 2012, 12:51

A couple of things that might help:

1) Colliders don't scale with the object they are attached to, they remain at a scale of 1
2) If an object is moving fast enough it can sometimes "jump over" another object between frames
neilb
Platinum Boarder
Platinum Boarder
 
Posts: 462
Location: Adelaide, South Australia

Re: Dynamic Collision Problem

Postby broozar » 21 Jun 2012, 13:24

walls and floors might have no thickness, so the "jumping over" effect neilb described is easier with those. use boxes, they have a thickness.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3347
Location: Berlin - Germany

Re: Dynamic Collision Problem

Postby MrGamer » 21 Jun 2012, 16:24

Thanks for your reply
I tried all the way as i can. I made wall with x 100, y = 10, and z=1, i set collider on it in model editor. if i use very slow speed velocity then it works but when i increased my speed then again i am getting same problem. I am using some api function to get information.
Code: Select all
if ( this.hHelperPlayer ( )~=nil )
then
   
    if (dynamics.getLastCollisionContactCount ( this.hHelperPlayer ( ) )>0 )
    then
        local hObj = dynamics.getLastCollisionContactObjectAt ( this.hHelperPlayer ( ),0)
        local sname = object.getModelName (hObj )
 
        if ( string.compare (  sname,"FlatWallComponentLarge" )==0)
        then
        log.message ( hObj )
        local x1,y1,z1 = dynamics.getLastCollisionContactPositionAt ( this.hHelperPlayer ( ), 1 )
    --  object.setTranslation ( this.hHelperPlayer ( ), x1,y1,z1,object.kGlobalSpace )
        object.resetTranslation ( this.hHelperPlayer ( ), object.kGlobalSpace )
        log.message ( x1, " , ",y1, " , ",z1 )
        end
    end
end


now sometimes it return me collision information and sometimes it does not return me anything.
Sometimes it prints more than one message on collision .
:?
MrGamer
Expert Boarder
Expert Boarder
 
Posts: 137

Re: Dynamic Collision Problem

Postby psychicsoftware » 21 Jun 2012, 20:41

did you try increasing the dynamics iterations per step, and/or reducing the dynamics timestep?

scene.setDynamicsIterationsPerStep ( hScene, nIterations )
scene.setDynamicsTimeStep ( hScene, nTimeStep )
User avatar
psychicsoftware
Platinum Boarder
Platinum Boarder
 
Posts: 338
Location: Galway, Ireland

Re: Dynamic Collision Problem

Postby MrGamer » 22 Jun 2012, 06:43

psychicsoftware wrote:did you try increasing the dynamics iterations per step, and/or reducing the dynamics timestep?

scene.setDynamicsIterationsPerStep ( hScene, nIterations )
scene.setDynamicsTimeStep ( hScene, nTimeStep )


Thanks i think it can help me could you tell me how to use it properly. please also could you tell me how much it affect on cpu usage.
8)
MrGamer
Expert Boarder
Expert Boarder
 
Posts: 137

Re: Dynamic Collision Problem  [SOLVED]

Postby psychicsoftware » 22 Jun 2012, 10:08

I can't recall what the default values are, I think maybe 1/120 for timestep. You can easily find out the defaults by using the scene.getXXX methods corresponding to these.

It will certainly affect CPU, yes. I think the important thing to do is to manage different device capabilities, and for this application.getAverageFrameTime is awesome.

Here's what I have done in one of my apps which has lots of physics objects, in order to support different device capabilities:

Code: Select all
--------------------------------------------------------------------------------
function LBS_MainAI.onThrottlePhysicsRate (  )
--------------------------------------------------------------------------------
   
    local s = application.getCurrentUserScene ( )
    local ft = application.getAverageFrameTime ( )
    if ( ft < 1/50 ) then
        scene.setDynamicsTimeStep ( s, 1/200 )
    elseif ( ft < 1/30 ) then
        scene.setDynamicsTimeStep ( s, 1/120 )
    else
        scene.setDynamicsTimeStep ( s, 1/60 )
    end
   
    this.postEvent ( 5, "onThrottlePhysicsRate" )
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------




You need to start this off by calling it once in your onInit handler. After that, it looks after itself and rechecks every 5 seconds to see if the physics timestep can be changed.

I'm not sure what the difference would be between tweaking timestep versus tweaking iterations per step. From working with open source engines, I would think that either would solve your problem - the difference would be when you need to accurately handle the interactions between multiple physics objects, then timestep is a better solution than iterations.. basically, if I'm right, every timestep each object is moved forward. When being moved forward, each object's movement is integrated over a number of iterations - the larger the number of iterations, the smaller each movement is and hence the less likely that a fast moving object will pass through things.
User avatar
psychicsoftware
Platinum Boarder
Platinum Boarder
 
Posts: 338
Location: Galway, Ireland


Return to Game programming