Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 16,005 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Yet another Rotate entity thread #124926
04/19/07 02:55
04/19/07 02:55
Joined: Sep 2006
Posts: 148
Ireng Offline OP
Member
Ireng  Offline OP
Member

Joined: Sep 2006
Posts: 148
How do I calculate efficiently the required angle to rotate from one entity to another?
My code is as follows


Code:
 
function is_ReturnAngleForTurningToEntity(eAgent,eTarget)
{
my=eAgent;
you=eTarget;

// get the direction from the entity MY to the entity YOU
vec_set(temp,you.x);
vec_sub(temp,my.x);
vec_to_angle(is_tempvec5,temp);

return(is_tempvec5.pan);
}

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; }
IF (result < 0) { my.pan -= rotate_speed * time; }
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; }
}

action player
{
while(my.pan!=is_tempvec5.pan)
{
rotate_entity(is_tempvec5.pan,30*time);
temp = abs(my.pan - is_tempvec5.pan);
if(temp<5){break;}
wait(1);
}
}




"When the battlefield is under total control, war becomes routine." Old Snake
Re: Yet another Rotate entity thread [Re: Ireng] #124927
04/19/07 03:17
04/19/07 03:17
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline
User
Trooper119  Offline
User

Joined: Apr 2004
Posts: 516
USA
Can you please elaborate what your trying to do with rotate, are you trying to get one entity to face another, two entities to rotate until the are face to face? or what, could be anything from what you describe.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: Yet another Rotate entity thread [Re: Trooper119] #124928
04/19/07 03:45
04/19/07 03:45
Joined: Sep 2006
Posts: 148
Ireng Offline OP
Member
Ireng  Offline OP
Member

Joined: Sep 2006
Posts: 148
Sorry for the lack of info.
I'm trying to make one entity rotate to face another one.
function is_ReturnAngleForTurningToEntity should calculate the pan difference required to face the target.
FUNCTION rotate_entity does the trick, but needs to be constantly updated.
So the action uses a while loop to keep the entity turning till it faces it's target.


"When the battlefield is under total control, war becomes routine." Old Snake
Re: Yet another Rotate entity thread [Re: Ireng] #124929
04/19/07 05:53
04/19/07 05:53
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline
User
Trooper119  Offline
User

Joined: Apr 2004
Posts: 516
USA
Alright, sorry I don't have more time but I have to get to work again, but with my first look over it seems that your nothing calls the function is_ReturnAngleForTurningToEntity(eAgent,eTarget) this means that is_tempvec5.pan is never existing in your action, you must call it in action so something like
-----------------------------------------
//Note you must define first_entity and second_entity to be the appropriate entities
is_tempvec5.pan = is_ReturnAngleForTurningToEntity(first_entity, second_entity);
//this must be right before

while(my.pan!=is_tempvec5.pan)

//to work
---------------------------------------
This is just a rough guess, but I've let you know what is definately wrong, I'm going to be busy for at least another day, so hopefully this will help you enough to get you going again.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: Yet another Rotate entity thread [Re: Ireng] #124930
04/19/07 08:40
04/19/07 08:40
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
This is what You need:
Code:
 

function player_move()
{
while(1)
{
vec_diff(temp,my_target,my.pos); //my_target maybe You ent pos
result = vec_to_angle(my_angle,temp);
my._speed = 10;
actor_turnto(my_angle.PAN)
wait(1);
}
}

function actor_turnto(angle)
{
angle = ang(angle - MY.PAN);
if (angle > 10) {temp = my._speed;}
else{
if(angle < -10){temp = -my._speed;}
else{temp = my._speed * angle * 0.1;}
}
MY.PAN += temp * time_step *2;//change this to faster turning
}



I've checked it and its 100% working

Last edited by tompo; 04/19/07 09:59.

Never say never.

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

Gamestudio download | 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