- Home /
how to calculate where an arrow will hit the enemy
I want to calculate where an arrow will hit the enemy before it actually hit him ,if it,s a headshot then the slow motion stuff. I,m not new to unity, i have done everything i could( raycast and projectile, search Google...) but it doesn't seem to work. So please please help!
Hey there,
you should probably split your problem in 2 seperate problems:
1: calculate where your arrow will be in "N" frames. 2: calculate where your enemys will be in N frames.
the First problem is a lot easier to solve than the second. If you want to i can write you some calculations and speudo-code for this if you provide me with some more info how your arrows are handled (e.g. do you use physics or a raycast for your arrows, speed etc) Especially the speed is interesting since the faster your arrow is your problem is far more easy to solve.
the second problem is a bit more difficult. How do you move enemys/targets? Nav agents? Do you have a "$$anonymous$$ovementpolicy"? How fast are your targets? How often do you recalculate what your targets are doing? Please put out some more info on this.
Thanks for reply Yeah i want to solve the first problem i can do the 2nd one.physics is use for arrows (rigidbody and forces). Raycast cant be used because the arrow do not travel in a straight line it moves like a mortar(projectile motion) basically in my game enemies are far enough less force is applied on the arrow and the player will have to figure out where he should aim to take a headshot.
Answer by Cynikal · Jul 28, 2018 at 04:54 PM
https://docs.unity3d.com/ScriptReference/RaycastHit-point.html
That will return the exact point the raycast hit.
You can then do something along the lines of if hit gameobject.name == "head" play slow motion.
(Using psuedo code...but you should know how to convert it)
Your answer