Where is my player looking?
by Mark Brown · in Torque Game Engine · 01/06/2009 (2:01 pm) · 5 replies
My player is standing inside a room.
There is a door on the south wall.
I want to tell my player where the door is.
If he is looking north, then "The door is behind you".
If he is looking east, then "The door is on your right".
I know what room he is in and where the door is.
I just don't know what direction he is looking.
Real code sample would be very helpful.
There is a door on the south wall.
I want to tell my player where the door is.
If he is looking north, then "The door is behind you".
If he is looking east, then "The door is on your right".
I know what room he is in and where the door is.
I just don't know what direction he is looking.
Real code sample would be very helpful.
About the author
#2
01/06/2009 (2:15 pm)
I'm on my way. Many thanks!
#3
%tform = ServerConnection.getControlObject().getEyeTransform();
%vec = VectorNormalize(ServerConnection.getControlObject().getForwardVector());
%vec = VectorScale(%vec, 4);
%tform = setWord(%tform, 0, getWord(%tform, 0) + getWord(%vec, 0));
%tform = setWord(%tform, 1, getWord(%tform, 1) + getWord(%vec, 1));
%tform = setWord(%tform, 2, getWord(%tform, 2) + getWord(%vec, 2));
But I still don't know if I am looking north, south, east, west.
It is probably some sort of conversion of the vector.
A bit of code is would be helpful.
Thanks again.
I have been building a randomly generated 3D maze for 2 years. Thousands of rooms in a library of rooms.
Nearly finished. Now working on the HELP command.
01/06/2009 (2:33 pm)
I found this bit of code:%tform = ServerConnection.getControlObject().getEyeTransform();
%vec = VectorNormalize(ServerConnection.getControlObject().getForwardVector());
%vec = VectorScale(%vec, 4);
%tform = setWord(%tform, 0, getWord(%tform, 0) + getWord(%vec, 0));
%tform = setWord(%tform, 1, getWord(%tform, 1) + getWord(%vec, 1));
%tform = setWord(%tform, 2, getWord(%tform, 2) + getWord(%vec, 2));
But I still don't know if I am looking north, south, east, west.
It is probably some sort of conversion of the vector.
A bit of code is would be helpful.
Thanks again.
I have been building a randomly generated 3D maze for 2 years. Thousands of rooms in a library of rooms.
Nearly finished. Now working on the HELP command.
#4
I don't remember which way is north with vectors, but if you do echo(%vec), you should be able to decipher which direction is which.
Hope that helps until someone better at this stuff comes in :-p
01/06/2009 (3:48 pm)
A vector is a type of structure that stores both direction and magnitude, stored in the form of x y z... if you normalize it, the length of that vector will be 1.I don't remember which way is north with vectors, but if you do echo(%vec), you should be able to decipher which direction is which.
Hope that helps until someone better at this stuff comes in :-p
#5
%jb = $global_player.getTransform ( );
%jc = getWord ( %jb, 6 );
%fixer = getWord ( %jb, 5 );
if ( %fixer < 0 )
{
%jc = 6.283 - %jc;
}
if ( %jc > 6.283 )
{
%jc = 6.283;
}
if ( %jc < 0 )
{
%jc = 0;
}
%angle = mFloor ( %jc * 57.296 );
echo ( "Compass Angle: " @ %angle );
%angle is a value from 0 to 359.
0 = North, 90 = East, 180 = South and 270 = West
Again, thanks for pointing!
01/06/2009 (7:11 pm)
My final solution:%jb = $global_player.getTransform ( );
%jc = getWord ( %jb, 6 );
%fixer = getWord ( %jb, 5 );
if ( %fixer < 0 )
{
%jc = 6.283 - %jc;
}
if ( %jc > 6.283 )
{
%jc = 6.283;
}
if ( %jc < 0 )
{
%jc = 0;
}
%angle = mFloor ( %jc * 57.296 );
echo ( "Compass Angle: " @ %angle );
%angle is a value from 0 to 359.
0 = North, 90 = East, 180 = South and 270 = West
Again, thanks for pointing!
Associate Orion Elenzil
Real Life Plus