Hi. i have a character and i want to make him fly and i want him to have a ghost ability (he can walk throw walls)
This is the flying code:
var targetDistance;
var target : Transform;
var moveSpeed = 8.0;
var damping = 3.0;
function Update ()
{
targetDistance = Vector3.Distance(target.position, transform.position);
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
var offsetDirection = target.position - transform.position;
offsetDirection.y = 0;
var rotation2 = Quaternion.LookRotation(offsetDirection);
transform.rotation = Quaternion.Slerp(transform.rotation2, rotation, Time.deltaTime * damping);
transform.Translate(offsetDirection.normalized * moveSpeed *Time.deltaTime, Space.World);
}
Attack this to the ghost, it will follow you allways at the same height.
For the ability of going through wall: just don’t put any colliders on the ghost. If you want it to collide with something: put all the collders on “Trigger”.