Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 559 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
determine relative angle #472218
04/16/18 20:49
04/16/18 20:49
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
I am playing around with angles and ran into a little thought error.

The actual moving character is the transparent box, while the animated model is simply attached to it.

The box always faces in the direction of where it is moving, while the animated character faces towards it`s enemy.

The attached character should play in relation to the angle of the transparent box the correct walking animation (strafe forward, left, right, back).



This is my attempt:




Code:
//calculate angle relation between [b]my[/b] and [b]enemy[/b]
var target_ang = abs(ang(bbox.pan - my.pan));



I can correctly define when the character is facingin the same or opposite direction as the box it is attached to.

Code:
//if ((target_ang >= 0) && (target_ang < 45))//facing within 45 degrees the same direction
//if ((target_ang >= 135) && (target_ang < 180))//facing within 45 degrees the opposite direction




However, determining if it is facing to the left or the right side, does not seem to work.

Code:
if ((target_ang >= 45) && (target_ang < 90))//facing within 45 degrees the left

if ((target_ang >= 90) && (target_ang < 135))//facing within 45 degrees the right




Could anybody point out my error?







Last edited by Blobfist; 04/16/18 21:29.
Re: determine relative angle [Re: Blobfist] #472227
04/17/18 11:01
04/17/18 11:01
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
one problem comes from removing the sign to 'target_ang'.

Code:
var target_ang = ang(bbox.pan - my.pan);
if (abs(target_ang) < 45) { // [-45, 45]
   // front
} else if (abs(target_ang < 135) { // [-135, -45], [45, 135]
   if (target_ang > 0) { // [45, 135]
      // left
   } else { // [-135, -45]
      // right
   }
} else { // [< -135][135 >]
   // back
}



if it is only to find the correct animation you might store their names in a TEXT and find its index from the angles.

Code:
TEXT *txtAnim = { string = ("front", "left", "back", "right"); }
...
var animIndex = floor((180 + ang(bbox.pan - my.pan - 22.5)) / 90);
ent_animate(me, (txtAnim.pstring)[animIndex], ...);



Salud!



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