- Home /
Question by
Censureret · Sep 26, 2020 at 12:15 PM ·
transformvector3
OnCollisionEnter direction
I have a projectile (spear) that can hit my enemies now depending on which angle the spear hits i need to play an animation on my character.
Now i need to figure out what side the spear hit the enemy (front, back, left,right) but as of now the current solution i have looked like this:
Vector3 toTarget = (other.gameObject.transform.position - transform.position).normalized;
Debug.Log(Vector3.Dot(toTarget, transform.forward));
if (Vector3.Dot(toTarget, transform.forward) > 0)
{
Debug.Log("Target is in front of this game object.");
}
else
{
Debug.Log("Target is not in front of this game object.");
}
However this only tells me front / back.
how do i find out if the character is hit from the side?
Comment
Your answer
Follow this Question
Related Questions
Finding the Angle Between Two Objects in 360 Degrees. 3 Answers
How to get a proper ramming effect? 1 Answer
Connecting transform with Vector3 4 Answers
unknown axis of rotation 1 Answer