Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Martin_HH, TipmyPip), 1,279 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
squik, AemStones, LucasJoshua, Baklazhan, Hanky27
19060 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Robot type movement. #48361
06/27/05 01:37
06/27/05 01:37
Joined: Sep 2003
Posts: 281
Arkansas\USA
raiden Offline OP
Member
raiden  Offline OP
Member

Joined: Sep 2003
Posts: 281
Arkansas\USA
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!

-raiden


"It doesn't matter if we win or lose, it's how we make the game."
--------------------
Links: 3DGS for Dummies
Re: Robot type movement. [Re: raiden] #48362
06/27/05 03:18
06/27/05 03:18
Joined: Sep 2003
Posts: 4,959
US
G
Grimber Offline
Expert
Grimber  Offline
Expert
G

Joined: Sep 2003
Posts: 4,959
US
tring to get the entity to turn only while it moves forward or backwards?

just a bit confused on the limited angles and what your trying to get.

Re: Robot type movement. [Re: Grimber] #48363
06/27/05 03:57
06/27/05 03:57
Joined: Sep 2003
Posts: 281
Arkansas\USA
raiden Offline OP
Member
raiden  Offline OP
Member

Joined: Sep 2003
Posts: 281
Arkansas\USA
Hi grimber, well the initial idea was to make an optimized turning code that when you press the arrow key, you turn in 90 degree increments, so if the robot was facing 0 pan, and I hit hit the left arrow key, it would turn its pan based on speed from 0-90, as well as for the other directions too.

The thing I found difficult was forcing the bot to turn the shortest directions to get to the target pan desired. My first attempts for a target of 0 pan, and the bots pan was at 270, the bot would go from 270, incrementing down to 0, this was the long route and didn't look right at all.

The seperate loops for the individual turning directions was the best I could come up with.

Also, the modes do keep the turning and movement seperate, seems more robotish to me if you seperate them.

Any suggestions to optimize the code grimber would be appreciated.

-raiden


"It doesn't matter if we win or lose, it's how we make the game."
--------------------
Links: 3DGS for Dummies

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1