About Store Forum Documentation Contact



Post Reply 
[Solved]geometry & math
Author Message
RedcrowProd Offline
Member

Post: #1
[Solved]geometry & math
hey,

i dont math very well. and i'm coming to you guys today for some help. it must be pretty simple, i just dont get it. pfft

first question :
what i'm trying to archieve : checking if angle is towards a point

i have 2 position pos1 and pos2 from the player and the attacker.
i have the angle for the player ( in radiant coming from the ctrl. as a flt [angle.x] )

i want to know if my player faces the attacker ( with a 90° margin ).

how can i archieve this mathematicaly ?

second question :

what i'm trying to archieve : get a line between my 2 points, and count 2 meters from my second point on that line

this one is under the same idea.

i have my player pos and the targetplayer pos, i have the player angle as well.

i want to push the targetplayer back 2m in the same direction from the player angle.


Would appreciate any helps,

Thanks !
(This post was last modified: 07-06-2016 03:44 AM by RedcrowProd.)
07-04-2016 01:42 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: Do you even math ?
1) I remember EE having AngleBetween, atleast there are quite a few Angle functions and Anglebetween comparison should be what you are looking for.(can't remember if this method returned degrees or radians)

2)"i want to push the targetplayer back 2m in the same direction from the player angle."
So what I understand you want to move the target away from the player? which would without using physics engine be pos(pos()+(-direction*2)); if only wanting 2d movement you need to do pos().x etc.

using the physics controller I think you only need to apply force to target, can't remember exactly the functions for this, but force(-direction*2);

I think this is correct but and I am just freehanding this and not going to test or do math check. pfft
(This post was last modified: 07-04-2016 02:05 AM by Zervox.)
07-04-2016 02:04 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #3
RE: Do you even math ?
hey !

1) idk why, but it seems that anglebetween when i tried it, is returning something like -0.029 and 0.029. and kinda random

Quote:bool al_anglefrom2point(Vec pos1, Vec pos2, flt angle1)
{
bool is=false; flt angle2=0;
Vec2 vec1=pos1.xz(), vec2=pos2.xz();

angle2=AngleBetween(vec1, vec2);

if(angle1+1<angle2 || angle1-1>angle2)is=true;

return is;
}

2) worked smile
(This post was last modified: 07-04-2016 06:05 AM by RedcrowProd.)
07-04-2016 04:51 AM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #4
RE: Do you even math ?
Hi, about the first problem you can do either:

A) Dot(PlayerOrientationVector, (EnemyPosition-PlayerPosition))

If the above is > 0 then your player is facing the enemy within the 90 degrees margin.

If you want the angle (radians) between the above two vectors you can take the Acos(Dot(...)) but you need to normalize the (EnemyPosition-PlayerPosition).

B) AbsAngleBetween(PlayerOrientationVector, (EnemyPosition-PlayerPosition))
Or you can simply use the above which returns the angle in radians in the range of [0..PI] and proceed to do your check (< PI)
(This post was last modified: 07-04-2016 12:47 PM by georgatos7.)
07-04-2016 10:13 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #5
RE: Do you even math ?
how do you build a playerorientationvector ?
(This post was last modified: 07-05-2016 05:49 AM by RedcrowProd.)
07-04-2016 04:21 PM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #6
RE: Do you even math ?
In your case the player orientation is probably one of the Right or Forward vectors that are contained in the player's matrix, this depends on how your player geometry is imported.

Both the A and B solutions above can work as Vec or Vec2 it depends on what you want to do.
(This post was last modified: 07-05-2016 01:20 AM by georgatos7.)
07-04-2016 08:59 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #7
RE: Do you even math ?
mhhh i think im just not getting it :(

what is wrong with what i am doing ?

Code:
bool al_anglefrom2point(Vec pos1, Vec pos2, flt angle1) // pos 1 & angle 1 is from defender point. pos2 is attacker
{
   bool is=false; flt angle2=0;
  
   Matrix PlayerOrientationVector; PlayerOrientationVector.setPos(pos1).rotateY(angle1);  
  
   angle2= AbsAngleBetween(PlayerOrientationVector.z, (pos2-pos1));
  
   return is;
}
(This post was last modified: 07-05-2016 05:47 AM by RedcrowProd.)
07-05-2016 01:23 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: Do you even math ?
Hi,

'setRotateY' will reset the matrix, and ignore your previous 'setPos' call
07-05-2016 04:21 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #9
RE: Do you even math ?
oh yeah, my bad on this one, i've just replaced it by rotateY ! thanks

i managed to make it work with vec2 smile

Quote:bool al_anglefrom2point(Vec pos1, Vec pos2, flt angle1) // pos 1 & angle 1 is from defender point. pos2 is attacker
{
bool is=false; flt angle2=0;
Vec2 t1=pos1.xz(), t2=pos2.xz();

Matrix PlayerOrientationVector; PlayerOrientationVector.setPos(pos1).rotateX(angle1);

angle2= AbsAngleBetween(Vec2(PlayerOrientationVector.z.y, PlayerOrientationVector.z.z), (t2-t1));

return is;
}

thanks to you guys smile
(This post was last modified: 07-05-2016 07:25 AM by RedcrowProd.)
07-05-2016 05:26 AM
Find all posts by this user Quote this message in a reply
Post Reply