trigonometry


How can I calculate the angle


I'm creating a game where if the enemy is in a certain range and is in front of the player the player can attack the enemy. I have worked out the radius distance and made it facing forward depending in which way the player faces but how can i create the angle so it makes like a cone shape from the player. I have got an image. The thin green line is the radius which I have worked out but how can i calculate the red cone.
Here is the image for more better understanding
http://tinypic.com/view.php?pic=28v63h0&s=6
This is what I done so far
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
public class Player extends MovieClip
{
var radius:Number = 60;
public function Player()
{
addEventListener(Event.ENTER_FRAME, Update);
}
function Update(event:Event)
{
var radiusx:Number = x+radius*Math.cos(rotation/180*Math.PI);
var radiusy:Number = y+radius*Math.sin(rotation/180*Math.PI);
// Rotate to mouse;
var dx = parent.mouseX - x;
var dy = parent.mouseY - y;
var angle = Math.atan2(dy,dx) / Math.PI * 180;
rotation = angle;
}
}
}
You can use the definition of tangent:
tan(a/2) = s/(2d)
where s is size (diamerer) of the enemy and d is the shortest distance to the enemy. Here a is the total visible angle (between two red lines).

Related Links

How can I calculate the angle
Finding Shortest Distance Between Two Parallel Lines, With Arbitrary Point [closed]
how to convert depth in Z-cordinate
How can I simplify this expression with trigonometric in Maple?
Require trigonometry assistance with ship/wave movement
Trigonometry - Find where two curves intersect
How to calculate point 'along' unit circle radian [closed]
Issues with bullet entry points for “shoulder mounted” guns
Using the coordinates of two of a triangle's vertices to calculate the coordinates of the third
How to do the trig function Arc Cos (ACOS() in Excel) in MS-Access?
How to get the direction (angle) of rectangle after rotating it from a pivot point
How to calculate points of Chord
Is trigonometry computationally expensive?
draw lines protruding from a circle [closed]
Flipping an angle using radians
Trigonometrical ratios for angles higher than 360

Categories

HOME
shell
kentico
checkstyle
dns
android-studio-2.2
apache-spark-mllib
access
javacc
carousel
emscripten
echo
tvos
google-chrome-app
android-securityexception
radgridview
android-intent
do-while
easyphp
xmonad
exploit
zxing
draft-js-plugins
pylons
intersystems-cache
ceylon
nsurl
dotspatial
kudu
mockjax
weather
jbutton
erb
code-snippets
dsx-desktop
hibernate-search
yowsup
xajax
sim-card
gdata
kill
magento-1.9.3
naming
dtsearch
manova
amq
oozie-coordinator
renaming
testrail
rocks
node-request
omxplayer
parfor
seek
xcode-server
envi
google-cloud-console
async.js
uicolor
expectations
upx
asyncdisplaykit
state-restoration
sony-lifelog-api
eoferror
uncompress
broadband
exceldatareader
ejb-2.x
delayed-execution
packet-sniffers
browserify-shim
entry-point
unix-socket
parallel-testing
cancellation
ray
memset
android-framework
drupal-nodes
kendo-dataviz
node-blade
jquery-1.9
insert-id
alice
tree-balancing
frameworkelementfactory
fragmenttransaction
database-create
usertype
uipagecontrol
codebase
instantiationexception
object-database
qtabbar
burndowncharts
mathematical-notation
interop-domino
windows-identity

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App