Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

Moving platforms (again)

All about the StoneScript

Moving platforms (again)

Postby freezer » 29 May 2012, 11:08

we have a dynamic platform with setKinematic to true, but the ball doesn't move with the platform.

so i first tried parenting to the platform using variations on the following

Code: Select all
    local hHitObj2, nHitDist2 = scene.getFirstHitSensorWithID (application.getCurrentUserScene(), x, y, z, 0, -1, 0, 0.6, 3)
   
    ---[[
    if(hHitObj2) then
        this.hParent(hHitObj2)
        object.setParent ( this.hThis(), hHitObj2, true )
    else
        if(this.hParent()) then
            object.setParent ( this.hThis(), nil, true )
           
            this.hParent(nil)
        end
    end


and when that sent our object mad i tried adding the platforms velocity (in various spaces)

Code: Select all
    if(hHitObj2) then
        local pvx, pvy, pvz = dynamics.getLinearVelocity(hHitObj2, object.kLocalSpace)
       
        local vx, vy, vz = dynamics.getLinearVelocity(this.hThis(), object.kGlobalSpace)
       
        --dynamics.setLinearVelocity(this.hThis(), vx+pvx, vy+pvy, vz+pvz, object.kGlobalSpace)
        dynamics.addLinearImpulse(this.hThis(), pvx, pvy, pvz, object.kLocalSpace)
       
    end


so at this moment i'm lost as what to try next...


a tutorial / code snippet / example would be great ;)
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Moving platforms (again)

Postby Fraser » 29 May 2012, 12:50

I tried the setkinematic route myself and ran into problems because my heros friction coefficient has to be low becaue I slide him about to move him using dynamics.addForce.

In your case the balls inertia might be causing it to roll off the platform instead of standing on it?

Now for moving platforms I use a normal collider object (not dynamics) and move with object.settranslation.

Of course the hero slides off the platform as it moves horizontally, so I made the platform have walls on it to push the hero left/right like this:

|_______|

This works OK, but if a platform is moving down then the hero will "rattle" constantly falling and landing on the platform top. Going up is fine.
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1086
Location: Europe

Re: Moving platforms (again)

Postby freezer » 29 May 2012, 12:58

hi and thanks,

we have the friction about 0.25 and the ball isn't rolling (it's sort of a fake ball at the moment, i.e. uses addForce).

really not after using sides (even invisible ones)

up and down is great using the dynamic method

the ball stays put (unless we apply movement) and the platform slides under it as it moves about


parenting either squishes the ball or flings it off somehow (quickly hitting an out of bounds sensor)
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Moving platforms (again)

Postby Fraser » 29 May 2012, 14:46

Have you set your platforms friction coefficient to 1?
Last edited by Fraser on 29 May 2012, 15:02, edited 2 times in total.
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1086
Location: Europe

Re: Moving platforms (again)

Postby freezer » 29 May 2012, 15:00

1 and also tried infinity too
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Moving platforms (again)

Postby Fraser » 29 May 2012, 15:08

Your pseudoball is rigged the same as my character, ball that does not rotate, I slide it about to move it with low friction coefficient.

I think I found setting ball to full friction did make it stick to platform, but then I couldn't move it around. I also had to reduce linear damping IIRC.

The only way I found to do horizontal platforms is with normal object colliders with walls.

This is a bit of a hack so I'd also like to know a better way to get it working.

here's what i've got so far:

http://youtu.be/2lGby5MbpzA
Fraser Ashworth,
https://www.cortex7.net
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1086
Location: Europe

Re: Moving platforms (again)

Postby dreamora » 29 May 2012, 15:44

one way to handle it is normally moving stuff on platforms along the platform itself through having it as child in the transform hierarchy so you can move the platform and all its childs get directly moved the same way too. This way all movement of the object on the platform becomes 'local to the platform' no longer global.

Trying to do it physically fails in most engines and technologies including PhysX and Havok actually, at least I've not seen a single case where it was not done through hierarchy so far.
I'm no stonetrip representative, just a happy board member like you :)

If you find my portfolio interesting, feel free to contact me or follow my shares on my twitter stream or my game development blog
User avatar
dreamora
Platinum Boarder
Platinum Boarder
 
Posts: 844

Re: Moving platforms (again)

Postby freezer » 29 May 2012, 16:01

when you say hierarchy, i tried parenting, but it squashed the ball or sent it flying (see above code)
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Moving platforms (again)

Postby dreamora » 29 May 2012, 19:38

Squashed -> you need to revert the scale the parent will apply to the child

Flying -> ensure that you apply forces in the right context. if you still apply them as if the object had no parent, you might at worst use the wrong coordinates - orientation and hence cause it to missbehave. you will likely want to ensure that you apply it in world coordinates instead of local coordinates
I'm no stonetrip representative, just a happy board member like you :)

If you find my portfolio interesting, feel free to contact me or follow my shares on my twitter stream or my game development blog
User avatar
dreamora
Platinum Boarder
Platinum Boarder
 
Posts: 844

Re: Moving platforms (again)

Postby freezer » 30 May 2012, 19:44

makes sense, i'll check it out soon ;)
too used to Blender...
freezer
Gold Boarder
Gold Boarder
 
Posts: 216


Return to Game programming

cron