Player rotation from trigger
by Mark Miley · in Torque Game Engine · 10/26/2003 (12:41 am) · 11 replies
I've been trying to figure something out for a couple days now. Everytime I think I get it I lose it again. What I'm trying to do is create a trigger that when the player enters the trigger it rotates the player 90 degrees to their left. It's for a side scroller. So the player is going straight and then hits the trigger and the continue to run in a new direction now...I'll deal with the camera updates later, but for now I'm just trying to get that core functionality in and I'm not sure how to access the transform for the player in script. I'm a little lost now as I've tried several examples from forum posts I've found and i'm not sure what i'm doing wrong.
About the author
#2
10/26/2003 (1:05 am)
Ok that's what I thought. Now can I run that same thing from the console? I'm just curious as I was trying to do that to see if it would get the player info and it kept giving me a can't find object '' blah blah blah.
#3
Then you could use PlayerName.setTransform(%newTransform); from anywhere (you dont need a local reference to the player). So you could stick that in a function in a server script, ie
Arg.. hope you understand that :D
10/26/2003 (4:55 am)
You can set up a function called i dunno... turnPlayerLeft, but you have to pass in some reference to the player. if have created the player with a name, ienew Player(PlayerName){
... blahblahblah
}; (There is something like this somewhere in your code...)Then you could use PlayerName.setTransform(%newTransform); from anywhere (you dont need a local reference to the player). So you could stick that in a function in a server script, ie
function turnPlayerLeft(){
.... do stuff to set up the new transform
PlayerName.setTransform(%newTransform);
}then you can call 'turnPlayerLeft();' from the console.Arg.. hope you understand that :D
#4
I know that this isn't right. What I'm trying to do and think that this code does do is store the position from gettranform into %pos. I think my problem is in the settransform. I'm not sure if that's the right way to put the information back into it. Obviously what I'm trying to do is keep the players original position but just change his rotation on the z axis. From the console command doc it looked like getwords could be used for this.
10/27/2003 (2:18 pm)
Thanks. I got that to work. On to my next question. I'm still trying to figure out the scripting langauge. function TurnPlayerLeft( )
{
%pos = getWords(janitor.getTransform(), 0, 2);
janitor.settransform(%pos @ "0 0 1 1.57");
}I know that this isn't right. What I'm trying to do and think that this code does do is store the position from gettranform into %pos. I think my problem is in the settransform. I'm not sure if that's the right way to put the information back into it. Obviously what I'm trying to do is keep the players original position but just change his rotation on the z axis. From the console command doc it looked like getwords could be used for this.
#5
Now this makes the player snap to the new direction. (the echo is in there for testing of course.) How do I make the player turn to the new direction on not just snap into that new rotation?
10/27/2003 (4:09 pm)
Ok I got the player the change rotation. Here is my code:function pTurn()
{
%pos = getWords(janitor.getTransform(), 0, 2);
%currAngle = getword(janitor.getTransform(), 6);
%newAngle = %currAngle - mDegToRad(90);
%trans = %pos SPC "0 0 1" SPC %newangle;
echo(%trans);
janitor.settransform(%trans);
}Now this makes the player snap to the new direction. (the echo is in there for testing of course.) How do I make the player turn to the new direction on not just snap into that new rotation?
#6
10/27/2003 (10:24 pm)
After trying several things I realized that there might be a better way to do this. I'm not sure how much work would be recquired, but I want the player to follow a given path. Say he hits the forward to run right(orientation to the camera as a side scrolling game) I want his motions to follow a given path so if he comes to a corner he will automatically change direction to meet the new direction of the path. I suppose there would have to be a tracer element...something that moves along the path just infront of him that would set the players view to that spot so he is always facing forward. Now the tricky part(i'm not sure if it's tricky, but it seems that way to me right now) is to get him to go the other way when hitting backwards...he would turn and run in the opposite direction along the path...orienting once again by the tracer. Any advice on what would be recquired...or recommendations or more questions would be very helpful. Thanks everyone. Hope I explained that clear enough.
#7
of course youd have to do something similar to the moveforward function or else he wont be able to turn forward again.
10/27/2003 (11:04 pm)
If you mean that he needs to turn around when the player pushes back, then you can just changefunction movebackward(%val)
{
$mvBackwardAction = %val;
}to say, function movebackward(%val)
{
..code to test to see if hes running backwards already
..code to turn him 180 degrees
moveforward(%val);
}of course youd have to do something similar to the moveforward function or else he wont be able to turn forward again.
#8
10/27/2003 (11:10 pm)
Also.. just a thought, but you could make it rotate in steps in the moveforward function so that he rotated when you hold forward (as well as moving forward) when some flag is set.
#9
10/28/2003 (12:44 pm)
Thanks for the suggestion. I am trying to find that function though and am not sure where to find it. Is it in the engine code or in script? I'm still a little new to torque.
#10
10/28/2003 (4:36 pm)
Found it! I added the code you outlined and it works perfectly. Thanks Dylan.
#11
player going this way (top view)
|
|player jumps, oh...say here
|
|
\/
trigger
-------------> new direction and correct path
|
|
|
\/
where the player lands...he is facing -->, but now he is way off the path
Hope that makes sense. How would I go about making it so he keeps the momentum, but it is used towards the new direction he is going in and not the old one?
~Mark
10/29/2003 (2:35 am)
Getting back to my original idea of using triggers to change player rotation(ie direction). I setup the triggers and played with them in the game and was all excited that it worked...but...I noticed that when i'm running and the player suddenly changes direction, upon hitting the trigger, he continues going in that direction for a moment and then continues straight down his new path. Well that was fine I thought. I'll just adjust my triggers to adjust to the sliding he does when abruptly changing direction. I was so clever I thought. That was until I realized that I had not tried jumping at a trigger. Uh oh! When the player hits the trigger in mid air he changes direction like I wanted but he keeps his momentum going and lands facing the right direction, but in the wrong place. Example:player going this way (top view)
|
|player jumps, oh...say here
|
|
\/
trigger
-------------> new direction and correct path
|
|
|
\/
where the player lands...he is facing -->, but now he is way off the path
Hope that makes sense. How would I go about making it so he keeps the momentum, but it is used towards the new direction he is going in and not the old one?
~Mark
Torque 3D Owner Robert Blanchet Jr.
Once you've got those values set do %player.setTransform(%yourValues); and you should be golden.