Quantcast
Channel: Questions in topic: "stay"
Viewing all articles
Browse latest Browse all 18

Keep an object on the gound.

$
0
0
Hello, I am using this script and the object I apply this script to floats in the air as it attempts to follow my character. How can I get the object to remain on the terrain as it follows my character? (the character changes heights on the terrain) Thank you. var target : Transform; //the enemy's target var moveSpeed = 3; //move speed var rotationSpeed = 3; //speed of turning var myTransform : Transform; //current transform data of this enemy function Awake() { myTransform = transform; //cache transform data for easy access/preformance } function Start() { target = GameObject.FindWithTag("Player").transform; //target the player } function Update () { //rotate to look at the player myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); //move towards the player myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; }

Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>