Game Development Community

How do I get an instance of a template object in TXB?

by Jason Hardesty · in General Discussion · 11/12/2007 (5:23 pm) · 1 replies

Im trying to create a homing missle that the player can fire. I used some of the code from Blaster and SpaceShooter tutorials. This is what I have for the seeking for the missile:

protected void _UpdateHomingAI(T2DSceneObject projectileObj)
{

_enemy = (T2DSceneObject)TorqueObjectDatabase.Instance.FindObject("EnemyTemplate");
_projectileObj = TorqueObjectDatabase.Instance.FindObject("ProjectileTemplate");

// determine angle to point our homing missile to the enemy
float angle = T2DVectorUtil.AngleFromTarget(projectileObj.Position, _enemy.Position);

// set the rotation of our homing missile
projectileObj.Rotation = angle;

// set the homing missile on its way towards the enemy
projectileObj.Physics.Velocity = T2DVectorUtil.VelocityFromTarget(projectileObj.Position,
_enemy.Position, 5.0f);
}

The problem is that the homing missle goes for the Enemy Template and not the the object that is spawned using the spawner object in TXB. How can I get the instance of the template? When an instance of the template enemy is created is a name given to the instance so it can be referenced and if this spawner keeps spawning enemies do the enemies all have different names so they can be referenced?

Thanks,
Jason

#1
11/13/2007 (6:39 am)
Even though you've posted this in the incorrect place twice, I'm going to point you to the TX and TXB forums to repost it and hopefully find a solution to your problem.

TX
TXB