Help with a particle effect during collision
by Josiah Hartzell · in Torque Game Builder · 08/24/2011 (3:42 pm) · 0 replies
Hello. I have a problem with displaying particles during a collision. Basically, the particle effect needs to be displayed when a ship is entering an atmosphere. I load the particle effect in script and stop the emitter. Now I have this code:
to accomplish this.
The shake effect works the whole time when I'm in the atmosphere of the planet (> 140.0 units from the center of the planet). However, the particle effect works in exactly the opposite. When I'm inside the atmosphere, the particles are disabled (even though I don't manually disable them anywhere) and when I'm outside of the atmosphere, the particles are enabled. This is very odd. Also, if I move playEffect() from within the if statement, it will only be displayed while I'm NOT colliding and be disabled while I AM colliding. What's going on here?
EDIT: Nevermind. I fixed it myself. I realized that playEffect() shouldn't be called every frame during the collision. My mistake.
Fixed with this:
function ShipControlBehavior::onCollision(%this, %srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
if(%srcObject.class != "PlanetAtmosphere")
return;
if(t2dVectorDistance(%this.owner.getPosition(), %srcObject.getPosition()) > 140.0)
{
sceneWindow2D.startCameraShake(4.0, 1.0);
%this.EntryEffect.playEffect();
}
}to accomplish this.
The shake effect works the whole time when I'm in the atmosphere of the planet (> 140.0 units from the center of the planet). However, the particle effect works in exactly the opposite. When I'm inside the atmosphere, the particles are disabled (even though I don't manually disable them anywhere) and when I'm outside of the atmosphere, the particles are enabled. This is very odd. Also, if I move playEffect() from within the if statement, it will only be displayed while I'm NOT colliding and be disabled while I AM colliding. What's going on here?
EDIT: Nevermind. I fixed it myself. I realized that playEffect() shouldn't be called every frame during the collision. My mistake.
Fixed with this:
function ShipControlBehavior::onCollision(%this, %srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
//string superclass = %this.owner.class;
if(%srcObject.class != "PlanetAtmosphere")
return;
if(t2dVectorDistance(%this.owner.getPosition(), %srcObject.getPosition()) > 140.0)
{
sceneWindow2D.startCameraShake(4.0, 1.0);
if(!%this.EntryEffect.getIsEffectPlaying())
%this.EntryEffect.playEffect();
}
}About the author