Last active
May 6, 2020 14:05
-
-
Save niuage/096b92b62d0c485b991137391e5cd245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// target is the player | |
// transform is the spider | |
Vector3 orientation = GetTerrainNormal(); | |
Vector3 directionToTarget = (target.position - transform.position).Y(0); | |
float d = Vector3.Dot(directionToTarget, orientation); | |
directionToTarget -= d * orientation; | |
if (directionToTarget.sqrMagnitude > 0.00001f) { | |
directionToTarget.Normalize(); | |
Quaternion rotationNeeded = Quaternion.LookRotation(directionToTarget, orientation); | |
transform.rotation = Quaternion.RotateTowards( | |
transform.rotation, | |
rotationNeeded, | |
xRotationSpeed * Time.deltaTime | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment