3d math question ?, script, aIplayer, mission Area
by Robert Brower · in General Discussion · 12/30/2002 (11:19 pm) · 7 replies
I have a question that relates to 3d math in torque script...
I want to add onLeaveMissionArea and onEnterMissionArea functions to my AIPlayer class and then spawn them in random locations within the mission area. I want them to spawn and move in a random direction in 3d space and at a random speed within an upper and lower speed limit. I think I can handle all of this.
Now...
When they leave the mission area I want to obtain the mission area box and calculate a rentry position, juxta position to the position at which they left the mission area so they wrap around to the other side of the mission area, reenter, and keep moving on their course.
I am having difficulty with figuring out how to calculate the rentry position. Does anyone have any tips, pointers, or advice that might help speed my efforts?
Thank you,
Robert
I want to add onLeaveMissionArea and onEnterMissionArea functions to my AIPlayer class and then spawn them in random locations within the mission area. I want them to spawn and move in a random direction in 3d space and at a random speed within an upper and lower speed limit. I think I can handle all of this.
Now...
When they leave the mission area I want to obtain the mission area box and calculate a rentry position, juxta position to the position at which they left the mission area so they wrap around to the other side of the mission area, reenter, and keep moving on their course.
I am having difficulty with figuring out how to calculate the rentry position. Does anyone have any tips, pointers, or advice that might help speed my efforts?
Thank you,
Robert
#2
12/31/2002 (10:57 am)
Thanks phil, that is where i am headed.
#3
function Asteroid::onLeaveMissionArea(%this, %obj)
{
%Transform = %obj.getTransform();
// get the mission area size
%missionArea = nameToID("MissionArea");
%area = %missionArea.getArea();
%mx1 = getWord(%area, 0);
%my1 = getWord(%area, 1);
%mw = getWord(%area, 2);
%mh = getWord(%area, 3);
%mx2 = %mx1 + %mw;
%my2 = %my1 + %mh;
// get the position of the asteroid
%oldax = getWord(%Transform, 0);
%olday = getWord(%Transform, 1);
%oldaz = getWord(%Transform, 2);
// initialize new location to old location
%newax = %oldax;
%neway = %olday;
%newaz = %oldaz;
// check min x
if (%oldax <= %mx1)
%newax = %oldax + (%mx2 - %mx1);
// check max x
if (%oldax >= %mx2)
%newax = %oldax - (%mx2 - %mx1);
// check min y
if (%olday <= %my1)
%neway = %olday + (%my2 - %my1);
// check max y
if (%olday >= %my2)
%neway = %olday - (%my2 - %my1);
%pos = %newax @ " " @ %neway @ " " @ %newaz;
%Transform2 = %pos @ " " @ getWord(%Transform, 3);
%obj.setTransform(%Transform2);
}
As you can see, I have not dealt with the Z axis. With the absence of a terrain block, can I use the flightCeiling property of the MissionArea object as a maximum Z coordinate? Then would the minimum Z coordinate be 0?
The other problem I am having is even though collisions are detected between the spacecraft and the asteroids (AIPlayers) the collision box seems to have been lost. I reexported my model using a collision box but I'm not feeling the thing as I can fly right through them. Interestly, onCollision does get called because I can push the asteroids around by flying into them, they just dont have the bumping into effect yet for some reason.
I worked out the colision problem. It's just a little tricky with 2 moving player objects but they work. I will add some applyImpulse script to both Player and Asteroid so that they bounce off each other like pool balls and take some damage. The problem was that I was spawning all the asteroids it the same spawn sphere and they were all colliding with each other and causing some trouble.
Any thoughts? Thank you...
Robert
01/01/2003 (2:00 pm)
I've got a working asteroid field now, but not to the extent that I want. Here is my function ->function Asteroid::onLeaveMissionArea(%this, %obj)
{
%Transform = %obj.getTransform();
// get the mission area size
%missionArea = nameToID("MissionArea");
%area = %missionArea.getArea();
%mx1 = getWord(%area, 0);
%my1 = getWord(%area, 1);
%mw = getWord(%area, 2);
%mh = getWord(%area, 3);
%mx2 = %mx1 + %mw;
%my2 = %my1 + %mh;
// get the position of the asteroid
%oldax = getWord(%Transform, 0);
%olday = getWord(%Transform, 1);
%oldaz = getWord(%Transform, 2);
// initialize new location to old location
%newax = %oldax;
%neway = %olday;
%newaz = %oldaz;
// check min x
if (%oldax <= %mx1)
%newax = %oldax + (%mx2 - %mx1);
// check max x
if (%oldax >= %mx2)
%newax = %oldax - (%mx2 - %mx1);
// check min y
if (%olday <= %my1)
%neway = %olday + (%my2 - %my1);
// check max y
if (%olday >= %my2)
%neway = %olday - (%my2 - %my1);
%pos = %newax @ " " @ %neway @ " " @ %newaz;
%Transform2 = %pos @ " " @ getWord(%Transform, 3);
%obj.setTransform(%Transform2);
}
As you can see, I have not dealt with the Z axis. With the absence of a terrain block, can I use the flightCeiling property of the MissionArea object as a maximum Z coordinate? Then would the minimum Z coordinate be 0?
The other problem I am having is even though collisions are detected between the spacecraft and the asteroids (AIPlayers) the collision box seems to have been lost. I reexported my model using a collision box but I'm not feeling the thing as I can fly right through them. Interestly, onCollision does get called because I can push the asteroids around by flying into them, they just dont have the bumping into effect yet for some reason.
I worked out the colision problem. It's just a little tricky with 2 moving player objects but they work. I will add some applyImpulse script to both Player and Asteroid so that they bounce off each other like pool balls and take some damage. The problem was that I was spawning all the asteroids it the same spawn sphere and they were all colliding with each other and causing some trouble.
Any thoughts? Thank you...
Robert
#4
Thanks =)
Robert
01/18/2003 (11:27 pm)
What is the max and min values for the Z axis in a given mission area? Is it related to Flight Ceiling? Am I misinterpretting the area? I thought it defined a 2d rect. Where is Z? Anyone?Thanks =)
Robert
#5
01/19/2003 (7:45 am)
It looks like there isn't one (except maybe flightCeiling). You could always add one to the code (if you own the SDK), or use schedule()ed callbacks to check each asteroid every so often and do something to it if it leaves the area...
#6
01/19/2003 (11:27 am)
I just used flight ceiling as the variance of the min and max z axis coord around zero. works fine. flight ceiling is relative to terrain which kinda floats in air far as i can tell. all is well.
#7
01/19/2003 (3:38 pm)
My mod for space environment rid the scene of ceiling knowledge. You can look through it to see what I did to remove it if that is what you need.
Torque 3D Owner Phil Carlisle
To wrap around, when they go off the bounds of one of the sides, say they go past the maximum X coordinate, simply subtract the difference between max and min X coordinates off thier current position.
If they go off the minimum X coordinate side, ADD the difference.
Same for Z, if you go less than min Z, ADD the z difference, if you go off max Z, subtract it.
Thats sounds to me like what you were after.
Phil.