Game Development Community

Projectiles collision scripts?

by James Haskins · in Torque Game Builder · 08/18/2008 (12:47 pm) · 1 replies

I have a ship that shoots other ships those ships have shields red, blue, yellow. I want to make it so the shields are only destroyed when the you fire the correct matching projectile (red, blue, yellow)

But the projectile still needs to be destroyed when it hits walls or shields of the wrong colour and also needs to destroy unshielded ships.

I was thinking of something along these lines to start with? Im pretty new to this so its probably totally wrong!


function shieldBlue:: onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)

{

if (%srcObj $= "ProjectileBlue") && (%dstObj $= "ShieldBlue")

{

safeDelete(%srcObj)
safeDelete(%dstObj)

}

}

If you guys could help me get on track with this i would be very gratefull. If there is any literature i could read that might help that would be cool too. Thanks in Advance folks

About the author

Recent Threads


#1
08/29/2008 (10:10 pm)
The code looks about right; just add a code block to delete only the projectile if it hits anything other than a blue shield. etc. (this would be within the function either above or below the current check.)

if (%srcObj $= "ProjectileBlue") && (%dstObj !$= "ShieldBlue")
     safeDelete(%srcObj)

the only other problem you might encounter with this is the way you are referencing the objects;
this may just be me, but I prefer to do it by class...

if (%srcObj.class $= "projectileBlueClass") && (%dstObj $= "shieldBlueClass")
     safeDelete(%srcObj)

, Eli