1 registered members (AndrewAMD),
1,393
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Angle between two entities
#118100
03/18/07 19:39
03/18/07 19:39
|
Joined: Mar 2006
Posts: 752 Portugal
demiGod
OP
User
|
OP
User
Joined: Mar 2006
Posts: 752
Portugal
|
Hi, This one its easy but i am making some confusion here, and after some tests i didnt figured it out yet, so i made a picture to help: Imagine two entities and a sphere, entity2 its always facing the sphere using vec_to_angle so no big deal (fig. 1). The problem is, when the sphere enters the black circle (i mean its distance to entity2 its less than x), entity2 no more turn towards the sphere, instead it stands in the angle when the sphere reached the circle (fig. 2). So, what i need to know is when the sphere reaches the circle, which is the angle between the entity2 and the sphere (relation between them) in order to know if the sphere travels in the LEFT or the RIGHT side of the entity2. Thanks in advance.
|
|
|
Re: Angle between two entities
[Re: demiGod]
#118102
03/19/07 23:35
03/19/07 23:35
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Well, I actually tried understanding your problem, but I failed.
#1 You want to have an entity, that always faces the sphere. #2 You solved that, by using vec_to_angle. #3 If the sphere comes close to a certain distance to the entity your algorithm quits working for whatever reasons.
Did I get your point? Can you post the code you wrote?
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Angle between two entities
[Re: Uhrwerk]
#118103
03/19/07 23:48
03/19/07 23:48
|
Joined: Mar 2006
Posts: 752 Portugal
demiGod
OP
User
|
OP
User
Joined: Mar 2006
Posts: 752
Portugal
|
First of all sorry for my poor english, maybe i didnt expressed myself well: The algorithm quits working when the sphere comes close to a certain distance to the entity2 because i want it that way, and that behavior its implemented with a simple skill: Code:
function ds_turnTowardsTarget(entTarget) { if(my._ds_turnTarget == 1) { you = entTarget; vec_set(temp,you.x); vec_sub(temp,my.x); vec_to_angle(my.pan,temp); my.tilt = 0; } }
I already solved the problem but not the way i want it, i just checked the pan of entity2 at a distance say 1000 quants and then compare that pan with the one when the sphere reached the circle (distance where entity2 no more faces the sphere). So, if the entity2 turned right i know the sphere will travel in the right side of the entity2 and so on. I know there is another (and correct) way to do it with vector angles but i didnt found the solution. Thanks.
|
|
|
Re: Angle between two entities
[Re: demiGod]
#118104
03/21/07 17:27
03/21/07 17:27
|
Joined: Sep 2006
Posts: 148
Ireng
Member
|
Member
Joined: Sep 2006
Posts: 148
|
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; } 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; } } Hope this helps. Works on one frame so put it inside a While loop.
Last edited by Ireng; 03/21/07 17:28.
"When the battlefield is under total control, war becomes routine."
Old Snake
|
|
|
Re: Angle between two entities
[Re: demiGod]
#118106
03/21/07 19:28
03/21/07 19:28
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
Code:
vec_set(temp,you.x); vec_sub(temp, my.x); vec_to_angle(myang, temp); my.bewegen_pan = sign(ang(myang.pan - my.pan));
my.bewegen_pan = -1 if the you Entity is on the left side. my.bewegen_pan = 1 if the you Entity is on the right side. I don´t know if this is the best way, but at least its working... Slin
|
|
|
|