- Home /
AI character model floats up when it follows the player!
im making a game and the character modle that i put the script onto makes the modle float up off the floor and then follows you. i even tryied puting a rigid body onto it but he just falls straight through the floor. i will attach the script i was using.
#pragma strict
var target : Transform; //the enemy's target
var moveSpeed = 1; //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;
}
the infamous forgotten command which Unity corporation sadly neglected to implement............
LookAt$$anonymous$$nees()
Answer by fafase · Aug 30, 2012 at 11:49 AM
The reason is probably because your enemy is smaller than the player so when looking at him, it adjusts the y-position. You should maybe use a character controller instead or modify the parameter of your Look rotation function so that instead of looking at the middle point, it looks below.
var newTarget:Vector3=Vector3(target.position.x,target.position.y-1,target.position.z);
transform.LookAt(newTarget);
You might have to change the 1 depending on the size of your guy.
how do i change the look rotation then (im new at this so im really bad at these things).
Your answer
Follow this Question
Related Questions
Character is floating 1 Answer
Why is my character not on the ground? 1 Answer
making a character float without reducing gravity 1 Answer
Character remains floating after walking up higher terrain. 2 Answers
3rd person 1 Answer