ShiVa3D
Grenade explosion - forces on objects- Collider solution
Paste down any little snippets or request a new one.Grenade explosion - forces on objects- Collider solution
by shivachristy » 30 Jan 2012, 14:55
This is the moment a grenade explodes forcing the surrounding objects away.
(The obvious scaling solution doesnt work how you would expect)
I have on my Avatars AI a variable called nExplode set to 0
In my scene I have created 4 cones and tagged them cone1,cone2,cone3,cone4.
cone 1 diameter 1 and height 1, cone 2 diameter and height 2 etc. these objects have a material set to opacity 0 and colliders are set on.
These cones are moved in to position in succession to emulate force.
so I have on my Avatars AI - a handler called onExplode
So I have my code that throws a grenade,tagged grenade -
this starts my countdown to call the above handler
object.postEvent ( this.getObject ( ),5,"AIAvatar","onExplode" )
I hope this helps someone.
(The obvious scaling solution doesnt work how you would expect)
I have on my Avatars AI a variable called nExplode set to 0
In my scene I have created 4 cones and tagged them cone1,cone2,cone3,cone4.
cone 1 diameter 1 and height 1, cone 2 diameter and height 2 etc. these objects have a material set to opacity 0 and colliders are set on.
These cones are moved in to position in succession to emulate force.
so I have on my Avatars AI - a handler called onExplode
- Code: Select all
function AIAvatar.onExplode ( )
--------------------------------------------------------------------------------
local hScene = application.getCurrentUserScene ( )
local hUser = application.getCurrentUser ( )
local nExplode = this.nExplode ( )
local grenade = scene.getTaggedObject ( hScene, "grenade" )
local cone1 = scene.getTaggedObject ( hScene, "cone1" )
local cone2 = scene.getTaggedObject ( hScene, "cone2" )
local cone3 = scene.getTaggedObject ( hScene, "cone3" )
local cone4 = scene.getTaggedObject ( hScene, "cone4" )
if (nExplode ==0 ) then
local X,Y,Z = object.getTranslation ( grenade,object.kGlobalSpace )
object.setTranslation ( grenade, 0, -100, 0, object.kGlobalSpace )
object.setTranslation ( cone1, X, Y, Z, object.kGlobalSpace )
end
if (nExplode ==1 ) then
local X,Y,Z = object.getTranslation ( cone1,object.kGlobalSpace )
object.setTranslation ( cone1, 0, -200, 0, object.kGlobalSpace )
object.setTranslation ( cone2, X, Y, Z, object.kGlobalSpace )
end
if (nExplode ==2 ) then
local X,Y,Z = object.getTranslation ( cone2,object.kGlobalSpace )
object.setTranslation ( cone2, 0, -300, 0, object.kGlobalSpace )
object.setTranslation ( cone3, X, Y, Z, object.kGlobalSpace )
end
if (nExplode ==3 ) then
local X,Y,Z = object.getTranslation ( cone3,object.kGlobalSpace )
object.setTranslation ( cone3, 0, -400, 0, object.kGlobalSpace )
object.setTranslation ( cone4, X, Y, Z, object.kGlobalSpace )
end
if(nExplode==4)then
object.setTranslation ( cone4, 0, -500, 0, object.kGlobalSpace )
this.nExplode ( 0)
else
this.nExplode ( nExplode + 1)
this.postEvent ( 0.1,"onExplode" )
end
--------------------------------------------------------------------------------
end
So I have my code that throws a grenade,tagged grenade -
this starts my countdown to call the above handler
object.postEvent ( this.getObject ( ),5,"AIAvatar","onExplode" )
I hope this helps someone.
-

shivachristy - Platinum Boarder

- Posts: 935
- Location: UK
Re: Grenade explosion - forces on objects- Collider solution
by Isabella8688 » 17 Mar 2012, 03:20
- Isabella8688
- Fresh Boarder

- Posts: 1
2 posts
• Page 1 of 1