- Home /
Question on Vector3.Reflect()
Hello everyone, I'm trying to get a specific result from a collision using Vector3.Relfect() which does not seem to be its default behavior:
I've seen Vector3.Reflect(), but In my case, I'm simulating (sort of) a cannon shell impacting iron armor, so I'm looking for more of a reflection vector like in my image below (a much flatter angle, where the shell almost "slides" along the armor after it deflects).
If anyone could show me a way of doing this or what math concepts I would need to get the result I'm after, I would greatly appreciate it.
Answer by Bunny83 · Oct 24, 2014 at 03:12 AM
Well, you could simply reflect it and then subtract a fractional part of the projected vector along the surface normal (well that sounds more complicated than it is :D)
Vector3 normal;
Vector3 incomingVelocity;
var reflected = Vector3.Reflect(incomingVelocity, normal);
var v = Vector3.Project(reflected, normal);
var result = reflected - v * 0.9f;
This would take away 90% from the distance of the reflected vector to the surface. So just imagine point R in your diagram goes straight downwards. If you use 1.0 instead of 0.9 the point R will be on the surface.
Just to explain what this actually does. This will keep 100% of the veloocity that is parallel to the surface but reduces the bounce of the velocity that is perpendicular to the surface.
That means if the inpact is straight down along the normal it won't move to the side since it doesn't have any velocity in that direction. It will bounce off back to where it's co$$anonymous$$g from but way slower (only 10%)
If the inpact is at a narrow angle the shell will almost slide along the surface with almost the same speed.
Interesting, I'll look into this. Thanks.
Update: Having a lot of fun with this, could not have done it without you.