Created
December 14, 2013 19:18
-
-
Save keiranlovett/7963596 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* Written by Cassius Adams for the Super Space Trooper video game. http://www.SuperSpaceTrooper.com */ | |
// Find the distance between weapon and Player so we can anticipate where Player will be | |
distance = Vector3.Distance(player.transform.position, transform.position); | |
// Divide distance by weaponSpeed to see how long it will take to get from Enemy to Player | |
var travelTime = distance / (Mathf.Abs(weaponSpeed) + playerSpeed); | |
// Multiply the amount of time by the speed the Player moves at | |
var futurePosition = travelTime * playerSpeed; | |
// Assign the new location that we want to point the weapons towards | |
var newLocation = Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z + futurePosition); | |
// Look at and dampen the rotation | |
var rotation = Quaternion.LookRotation(newLocation - transform.position); | |
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment