Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 730 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Enemy smoothly turn to player #171165
12/04/07 22:32
12/04/07 22:32
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
how can i smoothly turn an enemy to the player?

i tryed to adjust this code (from the manual) a bit

vec_set(temp,player.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);

i tryed to directly turn..put the vec's in a temp vec and rotate the enemy (my) to the tempvec like this

if(my.pan > my.temp_pan)
{
my.pan -= 5 * time;
}
if(my.pan < my.temp_pan)
{
my.pan += 5 * time;
}

this method works but not without 'bugs'

when the player moves over some certains axis the enemy needs to turn all arround his pan before pans right.

so how to make the enemys pan smoothly without problems ?

Re: Enemy smoothly turn to player [Re: Toon] #171166
12/05/07 04:16
12/05/07 04:16
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline
Expert
Puppeteer  Offline
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen

if(temppan>180)
{
temppan-=360;
}
if(temppan<-180)
{
temppan+=360;
}
// rotate stuff here
if(my.pan>180)
{
my.pan-=360;
}
if(my.pan<-180)
{
my.pan+=360;
}


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: Enemy smoothly turn to player [Re: Puppeteer] #171167
12/05/07 05:11
12/05/07 05:11
Joined: Sep 2003
Posts: 281
Arkansas\USA
raiden Offline
Member
raiden  Offline
Member

Joined: Sep 2003
Posts: 281
Arkansas\USA
Just another alternative for you:
Code:

//////////////////////////////
// Object Always Facing Player
//////////////////////////////

//variable defintions
var face_pos[3];//used to set position then distance
var face_ang[3];//used to subtract pan angles for turning ent
var face_trn[3];//limits the turning of the ent

//define definitions
define face_speed, 3; // change 3 to your turning speed

action face_main {
while(!player) { wait(1); }
while(1) {
vec_set(face_pos,my.x);
vec_sub(face_pos,player.x);
vec_to_angle(face_ang,face_pos);
face_trn.pan = ang(face_ang.pan - my.pan);
if(face_trn.pan < 0) { my.pan += face_speed * time; }
else { my.pan -= face_speed * time; }
wait(1);
}
}


//////////////////////////////
// End
//////////////////////////////



-raiden


"It doesn't matter if we win or lose, it's how we make the game."
--------------------
Links: 3DGS for Dummies
Re: Enemy smoothly turn to player [Re: raiden] #171168
12/05/07 14:15
12/05/07 14:15
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
Thanks Raiden! This is what im looking for! One thing...when the speed is increased a lot the model is 'shaking'

i tryed this but it doesnt seem to work:

Code:
 
if(face_trn.pan < -5)
{
my.pan += face_speed * time;
}
if(face_trn.pan > 5)
{
my.pan -= face_speed * time;
}



does anyone know how to fix this?

Re: Enemy smoothly turn to player [Re: Toon] #171169
12/05/07 14:50
12/05/07 14:50
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline
Expert
Puppeteer  Offline
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
You can use min/max!

if(face_trn.pan < 0) {my.pan += min(face_speed * time,face_trn.pan); }
else { my.pan += max(-face_speed * time,face_trn.pan); }


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: Enemy smoothly turn to player [Re: Puppeteer] #171170
12/10/07 17:10
12/10/07 17:10
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
this code works perfectly exept for its now face the opposite way then to the player..but the min max works against the shaking

Re: Enemy smoothly turn to player [Re: Toon] #171171
12/15/07 02:42
12/15/07 02:42
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline
Expert
mpdeveloper_B  Offline
Expert

Joined: Feb 2006
Posts: 2,185
here's one that i use:

Code:

FUNCTION rotate_entity_(rotate_angle,rotate_speed)
{
IF (my.pan == rotate_angle) { return; }
result = ang(rotate_angle - my.pan);
IF (result > 0) { my.pan += rotate_speed * time_step; }
IF (result < 0) { my.pan -= rotate_speed * time_step; }
IF (ang(rotate_angle - my.pan) < 0 && result > 0) { my.pan = rotate_angle; }
IF (ang(rotate_angle - my.pan) > 0 && result < 0) { my.pan = rotate_angle; }
}




to use it add these lines to the action of the object to face the player:

var pan_pos;
vec_to_angle (pan_pos, player);
rotate_entity_(pan_pos,5);


- aka Manslayer101

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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