Vectors don't like me...
by Kirby Webber · in Torque Game Engine · 08/19/2005 (5:48 pm) · 4 replies
What I'm trying to do seems rather simple - I'm running a radius search using containerFindFirst() to return interior objects (using interiors for testing).
> As a note, $Game::Player is declared in game.cs to make the client ID global.
When a target is returned, I'm trying to change the trajectory of the projectiles to target the selected object. Here's the code I'm currently using in chapeBaseImageData::onFire() function (see LabRats' deathcar tutorial).
Now, thought that by subtracting the current muzzle vector from the location/ vector returned by containerFindFirst() that the projectile would target the current... well, target.
I'm no 3D math wiz, so any input, advice or insights anyone could provide would be most welcome...
[EDIT]
As I experiment, I'm beginning to wonder - does containerFindFirst() only return on objectID? That seems to be the case... I've used echo statements in conjunction with getWord() to test for additional information and all I get is the ID.
=\
> As a note, $Game::Player is declared in game.cs to make the client ID global.
function targetAssist(){
%mask = $TypeMasks::InteriorObjectType;
%eye = $Game::Player.getEyeTransform();
%radius = 100; //container radius
%target = containerFindFirst(%mask, %eye, %radius, %radius, %radius);
return %target;
}//end targetAssist()When a target is returned, I'm trying to change the trajectory of the projectiles to target the selected object. Here's the code I'm currently using in chapeBaseImageData::onFire() function (see LabRats' deathcar tutorial).
function ShapeBaseImageData::onFire(%data, %obj, %slot)
{
%projectile = %data.projectile;
%mVec = %obj.getMuzzleVector(%slot);
%target = targetAssist();
%muzzleVector = vectorsub(%mVec, %target);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
... (snipped for brevity)Now, thought that by subtracting the current muzzle vector from the location/ vector returned by containerFindFirst() that the projectile would target the current... well, target.
I'm no 3D math wiz, so any input, advice or insights anyone could provide would be most welcome...
[EDIT]
As I experiment, I'm beginning to wonder - does containerFindFirst() only return on objectID? That seems to be the case... I've used echo statements in conjunction with getWord() to test for additional information and all I get is the ID.
=\
#2
The question I'm researching now is, what function do I use to get the world transform of an object by its ID?
=\
08/19/2005 (9:09 pm)
Point taken Eric. (C:The question I'm researching now is, what function do I use to get the world transform of an object by its ID?
=\
#3
If you want it's transform it's .getTransform().
This is of course assuming the objects your working with are derived from ShapeBase.
- Eric
08/19/2005 (9:13 pm)
If you want it's position (most likely) it's .getPosition().If you want it's transform it's .getTransform().
This is of course assuming the objects your working with are derived from ShapeBase.
- Eric
#4
Thanks Eric. =)
08/19/2005 (9:22 pm)
~Doh... you know, about three iterations back I was playing with getPosition(), but since that time I've been digging through so much 3D vector math I'd forgotten it.Thanks Eric. =)
Torque 3D Owner Eric Roberts
That would definately explain any oddities you've already encountered.
Use Torsion or TorqueDev and use the debugger! Copy and paste those variables and watch them so you don't have to use "echo()" all of the time.
Another problem I see occurring is that your muzzleVector isn't normalized before you scale it by it's muzzleVelocity. You'll get a much larger velocity than you'll anticipate if you don't normalize the vector first (make the vector keep it's same direction but have a magnitude of one).
So normalize it first!
Another little tip - try to be a little more descriptive (but brief) when it comes to subject posts. Deciding Vectors "hate you" just leads people to believe you have a hatred for vectors and a possibly a problem. The better the subject, the more likely to get a faster and more accurate response.
Hope it helps,
- Eric