Well, not much of a contribution, but since I spent a ton of time trying to find the best approach to this, maybe someone will find it handy.
Basically it uses the cursor keys and rotates the entity in 90 or 180 degree pan increments depending on which direction it is facing and which key is hit, and moves the robot forward or backwards on the mouse_clicks.
--IMPORTANT NOTE - This is only for objects that will face in the pan directions of: 0, 90, 180, 270. If your entities pan is not facing these directions, they will not turn. -- Code:
//face directions
define face_up, 0;
define face_down, 180;
define face_right, 270;
define face_left, 90;
define speed, skill18;//movement speed
define turnspeed, skill19;//turning speed
define energy, skill20;//health
//movement distances
define force_x, skill46;
define force_y, skill47;
define force_z, skill48;
//stores and sets robot states
define mode_move, skill49;
define no_turn, 0;
define turn, 1;
define mode_turn, skill50;
define no_move, 0;
define move, 1;
//a pointer to the robot
entity* player;
//turning function
function face_direction(targ,dir){
while(my.mode_turn == turn && dir == 0) {
if(targ == 90 && dir == 0) {
my.pan = min(targ,(abs(my.pan)+my.turnspeed*time));
}
if(targ == 180 && dir == 0) {
my.pan = min(targ,(abs(my.pan)+my.turnspeed*time));
}
if(targ == 270 && dir == 0) {
if(my.pan == 0) { my.pan = 360; }
my.pan = max(targ,(abs(my.pan)-my.turnspeed*time));
}
if(my.pan == targ) { my.mode_turn = no_turn; my.mode_move = move; }
wait(1);
}
while(my.mode_turn == turn && dir == 90) {
if(targ == 0 && dir == 90) {
my.pan = max(targ,(abs(my.pan)-my.turnspeed*time));
}
if(targ == 180 && dir == 90) {
my.pan = min(targ,(abs(my.pan)+my.turnspeed*time));
}
if(targ == 270 && dir == 90) {
my.pan = min(targ,(abs(my.pan)+my.turnspeed*time));
}
if(my.pan == targ) { my.mode_turn = no_turn; my.mode_move = move; }
wait(1);
}
while(my.mode_turn == turn && dir == 180) {
if(targ == 0 && dir == 180) {
my.pan = max(targ,(abs(my.pan)-my.turnspeed*time));
}
if(targ == 90 && dir == 180) {
my.pan = max(targ,(abs(my.pan)-my.turnspeed*time));
}
if(targ == 270 && dir == 180) {
my.pan = min(targ,(abs(my.pan)+my.turnspeed*time));
}
if(my.pan == targ) { my.mode_turn = no_turn; my.mode_move = move; }
wait(1);
}
while(my.mode_turn == turn && dir == 270) {
if(targ == 0 || targ == 360 && dir == 270) {
targ = 360;
my.pan = min(targ,(abs(my.pan)+my.turnspeed*time));
if(my.pan == 360) { my.pan = 0; targ = my.pan; }
}
if(targ == 90 && dir == 270) {
my.pan = max(targ,(abs(my.pan)-my.turnspeed*time));
}
if(targ == 180 && dir == 270) {
my.pan = max(targ,(abs(my.pan)-my.turnspeed*time));
}
if(my.pan == targ) { my.mode_turn = no_turn; my.mode_move = move; }
wait(1);
}
}
//robot action
action player_robot {
player = me;
if(my.speed == 0) { my.speed = 10; }//default move speed
if(my.turnspeed == 0) { my.turnspeed = 3; }//default turn speed
if(my.energy == 0) { my.energy = 100; }//default health
my.force_x = 0;
my.mode_move = move;
my.mode_turn = no_turn;
while(my.energy > 0) {
//face directions
if(key_cuu && my.mode_turn == no_turn && my.mode_move == no_move) {
my.mode_turn = turn; face_direction(face_up,my.pan);
}
if(key_cud && my.mode_turn == no_turn && my.mode_move == no_move) {
my.mode_turn = turn; face_direction(face_down,my.pan);
}
if(key_cul && my.mode_turn == no_turn && my.mode_turn == no_move) {
my.mode_turn = turn; face_direction(face_left,my.pan);
}
if(key_cur && my.mode_turn == no_turn && my.mode_move == no_move) {
my.mode_turn = turn; face_direction(face_right,my.pan);
}
//move directions
if(mouse_left == 1 && my.mode_turn == no_turn) {//forward
my.force_x = my.speed;
}
if(mouse_right == 1 && my.mode_turn == no_turn) {//reverse
my.force_x = -my.speed;
}
if(mouse_left == 1 && mouse_right == 1
|| mouse_left == 0 && mouse_right == 0) {
my.mode_move = no_move;
my.force_x = 0;
}
move_mode = ignore_passents + ignore_sprites + activate_trigger;
ent_move(vector(my.force_x*time,0,0),nullvector);
wait(1);
}
}
Hope you find it useful!
![](/ubbthreads/images/graemlins/laugh.gif)
-raiden