- Home /
Reflection Angle - Change objects rotation
Hi guys,
Having some problems getting an object to rotate away from a collision down the angle of reflection. We've tried vector3.reflect but it doesn't seem to be helping us too much.
Does anyone have any good ideas or reference?
Thanks!
-Jack
Answer by Cyb3rManiak · Apr 21, 2011 at 01:13 PM
No reference I'm afraid, but the basic idea is to use Quaternion.SetFromToRotation along with Vector3.Reflect...
This is guess work on my part about what exactly you want to accomplish, but try this and tweak it to your liking (untested!!! Parts copy paste from old code, parts just made up right now.)
private var hitInfo : RaycastHit; private var fRayDistance : float = 100;
if (Physics.Raycast(v3Origin, v3Direction, hitInfo, fRayDistance, layerMask.value)) { var v3NewDirection: Vector3 = Vector3.Reflect (hitInfo.point - v3Origin.point, hitInfo.normal).normalized; var qNewRotation: Quaternion = SetFromToRotation (hitInfo.normal, v3NewDirection);
// Do whatever Lerp/Slerp you want...
}