How To Make Your Character Move A Set Ammount?
by David Smith · in Technical Issues · 06/28/2007 (10:56 am) · 8 replies
How would I go about making my character moving a set ammount when the movement key is pressed? I'm working on a game similar to Kula World (for educational purposes), where you will play as a box that turns on it's different faces to move around a 3-dimensional level.
Any help is appreciated.
Any help is appreciated.
#2
06/28/2007 (11:00 am)
That doesn't help. I knew that already. But that gives me flowing movement, which is not what I want to achieve.
#3
There's more than one way to do this... here is one that works. It teleports the spellcaster forward 10 feet:
I added code to avoid the disaster of teleporting below ground, however, there is still potential trouble with teleporting below the floor of an interior or inside trees, etc.
06/28/2007 (11:33 am)
Here is something that I found on the AFX forums. Since it does involve the AFX kit, there will need to be some alterations made to many of the variables used, but the idea is there I believe.Quote:
What i'm trying to figure out is how to use '.getDirection' or something similar to teleport forwards, backwards, etc, and not always north or south. Anyone have an idea how to do that?
There's more than one way to do this... here is one that works. It teleports the spellcaster forward 10 feet:
// get the facing vector of the caster %fwd_vec = %caster.getForwardVector(); // make the vector the desired length %fwd_vec_norm = VectorNormalize(%fwd_vec); %fwd_vec_tele = VectorScale(%fwd_vec_norm, 10); // add the teleport vector to the caster's position %caster_pos = %caster.getPosition(); %tele_pos = VectorAdd(%caster_pos, %fwd_vec_tele); // adjust destination position to terrain height %new_ht = getTerrainHeight(%tele_pos); %pos_x = getWord(%tele_pos,0); %pos_y = getWord(%tele_pos,1); %caster.setTransform(%pos_x SPC %pos_y SPC %new_ht);
I added code to avoid the disaster of teleporting below ground, however, there is still potential trouble with teleporting below the floor of an interior or inside trees, etc.
#4
06/28/2007 (11:38 am)
Please note that %caster is an AFX variable that represents the caster of the spell or ability (usually representing the player). With a little alterations, you could use something like this in the function that is called when the player presses the 'W', 'A', 'S', or 'D' keys (or whatever you have them binded to).
#5
Also, how would I go about making the brick rotation rotate according to the Camera Angle (when the brick turns onto a new face)?
For instance, you're facing North, you press W, and your brick goes forward and rotates onto its front face. But, when you turn to face East, and you press W, it will move to your left and turn onto that face.
How do I make it so it moves forward/back/left/right according to the direction you're facing, instead of a set direction?
[EDIT] I changed %caster to %client, and it didn't work. I figrued this might be because it's in single player. So I changed it to %player, and it still didn't work. I couldn't see any other variables that should need changing. Am I doing something wrong?
I figured changing vec to something else might help, but I'm not sure what. Any suggestions? Thanks.
06/28/2007 (11:48 am)
Thanks, muchly appreciated.Also, how would I go about making the brick rotation rotate according to the Camera Angle (when the brick turns onto a new face)?
For instance, you're facing North, you press W, and your brick goes forward and rotates onto its front face. But, when you turn to face East, and you press W, it will move to your left and turn onto that face.
How do I make it so it moves forward/back/left/right according to the direction you're facing, instead of a set direction?
[EDIT] I changed %caster to %client, and it didn't work. I figrued this might be because it's in single player. So I changed it to %player, and it still didn't work. I couldn't see any other variables that should need changing. Am I doing something wrong?
Quote:function moveForwardLol()
{
%fwd_vec = %client.getForwardVector();
%fwd_vec_norm = VectorNormalize(%fwd_vec);
%fwd_vec_tele = VectorScale(%fwd_vec_norm, 10);
%client_pos = %client.getPosition();
%tele_pos = VectorAdd(%client_pos, %fwd_vec_tele);
%new_ht = getTerrainHeight(%tele_pos);
%pos_x = getWord(%tele_pos,0);
%pos_y = getWord(%tele_pos,1);
%client.setTransform(%pos_x SPC %pos_y SPC %new_ht);
}
moveMap.bindCmd(keyboard, "x", "", "moveForwardLol();");
I figured changing vec to something else might help, but I'm not sure what. Any suggestions? Thanks.
#6
It really depends on where you are trying to call these, I think.
Regarding the rotation, please have a look at this quote.
From: www.garagegames.com/mg/forums/result.thread.php?qt=21280
06/28/2007 (12:22 pm)
Regarding your question above (the edited one), try %client.player.functionName().It really depends on where you are trying to call these, I think.
Regarding the rotation, please have a look at this quote.
From: www.garagegames.com/mg/forums/result.thread.php?qt=21280
Quote:
To new spawners :)
It might help to understand the transform structure.
There are 7 numbers in the transform matrix, such as the default "0 0 300 1 0 0 0"
The first three are the x, y, and z position (usually the easiest to understand).
The second three are the rotation axis x, y, and z. This is usually the problem as the default of "1 0 0" actualy creates a rotation around the x axis which is why the players end up on their head as it rotates them forward. Now, since most people want to simply turn their player to a different heading, the rotation axis should be "0 0 1". This will solve most problems.
The last number is the rotation amount in RADIANS. A 360 degree turn is 2 PI or 6.28, a 180 degree turn is PI or 3.14, and a 90 degree turn is half PI or 1.57.
Getting terrain height is usually an issue as well, and I wish a certain command was better publicised (i,e in the demo).
%spawn = %group.getObject(%index);
%point = getWords(%spawn, 0, 1); // this gets the x and y position
// if you're using a spawn point, get the rotation otherwise you can set it directly
%rot = getWord(%spawn, 6);
%z = getTerrainHeight(%point);
// if you want to add a little to make them fall or bounce
// %z += 1;
%spawn = %point SPC %z SPC "0 0 1" SPC %rot;
Voila, you are perfectly on the terrain in the right rotation.
#7
06/29/2007 (4:13 am)
Maybe destroying the object, and then respawn it with the exact same properties at the location you want it to tele-frag to?
#8
And server side you would have
07/20/2007 (5:07 pm)
Hey David, the problem with your function there is that it needs to be server side, as that is where all the client data is stored. In that function, you don't actually have a variable storing the client data. What you want to do is create a bind like this:moveMap.bindCmd(keyboard, "x", "", "commandToServer('MoveForward');", "");And server side you would have
function serverCmdMoveForward(%client)
{
%fwd_vec = %client.getForwardVector();
%fwd_vec_norm = VectorNormalize(%fwd_vec);
%fwd_vec_tele = VectorScale(%fwd_vec_norm, 10);
%client_pos = %client.getPosition();
%tele_pos = VectorAdd(%client_pos, %fwd_vec_tele);
%new_ht = getTerrainHeight(%tele_pos);
%pos_x = getWord(%tele_pos,0);
%pos_y = getWord(%tele_pos,1);
%client.setTransform(%pos_x SPC %pos_y SPC %new_ht);
}
Torque Owner Berserk