Gamestudio Links
Zorro Links
Newest Posts
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,393 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Angle between two entities #118100
03/18/07 19:39
03/18/07 19:39
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline 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] #118101
03/19/07 20:30
03/19/07 20:30
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Hey, no ideas?

A simple workaround for this question its just check the angle at two different positions like when the sphere is near entity1 and then when it reaches the circle. Then just compare the two angles and see if it increased or decreased and we know if the sphere will be at entity2´s left or right.

But there is a better and correct way to do it (vec_for_angle i believe) but i just dont found it yet.

Dont believe there is no ideas about that, strange...

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 Offline
Expert
Uhrwerk  Offline
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 Offline OP
User
demiGod  Offline 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 Offline
Member
Ireng  Offline
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: Ireng] #118105
03/21/07 19:09
03/21/07 19:09
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Hi Irenq,
thanks for your code, but i dont want to rotate the entity, just need to know if the sphere is in the right or left side of entity2..

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 Offline
Expert
Slin  Offline
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

Re: Angle between two entities [Re: Slin] #118107
03/21/07 20:39
03/21/07 20:39
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Hi Slin !

It seems to be what i was looking for indeed, a simple and efective way, much better than the solution i had implemented comparing the pan at two different moments.

Very good Slin, it works like a charm, thank you for your time.


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