muzzleVelo"> Create Projectile from C | Torque Game Engine | Forums | Community | GarageGames.com

Game Development Community

Create Projectile from C

by Stephane Savioz · in Torque Game Engine · 09/14/2005 (7:11 am) · 2 replies

How to create a projectile from the C++ code :

I've tried the following code :

ProjectileData* projData = new ProjectileData();
projData->projectileShapeName = "d:/torque/heidi/control/data/models/3dstest/sphere.dts";

projData->muzzleVelocity = 1; //Speed of the Projectile when fired
projData->velInheritFactor = 0; //[0,1] scale of how much velocity should be inherited from the parent object
projData->armingDelay = 0 ; //0.3;
projData->lifetime = 50000;
projData->fadeDelay = 50000;
projData->bounceElasticity = 0;
projData->bounceFriction = 0;
projData->isBallistic = true;
projData->gravityMod = 0.10;
projData->hasLight = false;
projData->lightRadius = 1.5;
ColorF colLight(0.56, 0.36, 0.26, 1.0);
projData->lightColor = colLight;

mMissile = new Projectile();
mMissile->setDataBlock(projData);

Is that the correct way to do it ?

#1
09/14/2005 (10:50 am)
You need to call registerObject() on mMissile. Also, the naming suggests you are storing a reference to the object somewhere. Make sure you use a SimObjectPtr<> or do something else that will deal with the deletion of the projectile alright, otherwise you'll have a stale pointer.
#2
09/15/2005 (2:08 am)
Thank you Ben,

perfect, exactly what I needed.

thanks