- Home /
Projectile reflection
I'm sorry if this question is already answered before, but I can't really figure out how to do this. I have a Projectile script that handles movement:
public Vector3 directionVector = Vector3.forward;
public virtual void ProjectileUpdate() {
transform.Translate(directionVector * Time.deltaTime * speed);
}
Now when this projectile triggers with something else, I'm trying to achieve a reflect effect, although I'm not really sure how to do this. Currently I'm just changing the direction to Vector3.back:
public override void ProjectileCollision(Collider trigger)
{
if (trigger.GetComponent<PlayerStats>().reflectiveShieldIsActive)
{
hasBeenReflected = true;
directionVector = Vector3.back;
return;
}
}
I'm not sure how the Vector3.Reflect method works, since I can't find a lot of information about it. How can I achieve a mildly realistic reflect effect? Thanks in advance!
Answer by beppim · Nov 18, 2015 at 05:01 PM
You need to know the normal of the surface of the reflecting object, then use Vector3.Reflect
http://docs.unity3d.com/ScriptReference/Vector3.Reflect.html
Here's how to compute the normal: http://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html
Using the contact point you can determine the exact normal of the point where the hit was: http://docs.unity3d.com/ScriptReference/Collision-contacts.html
Your answer
Follow this Question
Related Questions
How to translate an empty? 2 Answers
New Unity problem 1 Answer
OnTriggerEnter2D not detecting 1 Answer
Only One LineRenderer Renders 0 Answers