[Solved]geometry & math Author Message
RedcrowProd
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. 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
Zervox
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. (This post was last modified: 07-04-2016 02:05 AM by Zervox.)
07-04-2016 02:04 AM
RedcrowProd
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+1angle2)is=true; return is; } 2) worked (This post was last modified: 07-04-2016 06:05 AM by RedcrowProd.)
07-04-2016 04:51 AM
georgatos7
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
RedcrowProd
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
georgatos7
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
RedcrowProd
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
Esenthel