≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
How to get angle between 2 object
Posted by:
(you are not logged in)
Enter the missing letter in: "Internationa?"
(you are not logged in)
Text:
[quote][b][/b] wrote: so i create function like this: [code] function findAngle(x1,z1,x2,z2){ var A = (x2 - x1); var B = (z2 - z1); var angle = Math.atan(A / B); if(B < 0) angle = angle + Math.PI; return angle * 57.29; } [/code] or [code] function findAngle(x1,z1,x2,z2){ if((z2 - z1) < 0) return (Math.atan((x2 - x1) / (z2 - z1)) + Math.PI) * 57.29; else return Math.atan((x2 - x1) / (z2 - z1)) * 57.29; } [/code] i know this code based on 2-dimensional space but it's totally do what i need, return angle between 2 object, i made it by myself so you can find some better way. "Thank, but I also need to view it form different angle (8 direction), so probably need some math here." you can setup direction of enemy then check angle to player and change texture to one of your 8 image P.S. there is one drawback, the angle is returned in the range from -90 to 270 [code] angle = angle * 57.29; if((angle ) < 0) angle = 360 + angle ; return angle ; [/code] add this and from 0 to 360[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact