Question by
freedom667 · Dec 20, 2015 at 07:11 PM ·
c#unity 5camerajavascriptfollow player
camera falling down when following player!!
I tried many scripts but nothing works. I will go crazy. what can i do for this?? when my player holding to rope main camera slips down.
Please take a look: https://sendvid.com/mziuem3u
Follow Script:
#pragma strict
var cameraTarget : GameObject; // Inspector> Assign the Camera Target NON è il target della camera ma la posizione che vuole raggiungere la camera
var smoothTime : float = 0.1; // Delay in seconds to follow Player
var cameraFollowX : boolean = true; // Inspector> if is checked -> The Camera will follow X position of cameraTarget
var cameraFollowY : boolean = true; // Inspector> if is checked -> The Camera will follow Y position of cameraTarget
var cameraFollowHeight : boolean = false; // if true the Camera Y Position = cameraHeight
var cameraHeight : float = 2.5; // cameraHeight
var velocity : Vector2;
var offset : float;
private var thisTransform : Transform;
function Start ()
{
thisTransform = transform;
}
function Update ()
{
if (cameraFollowX) // if cameraFollowX = true = Inspector is checked
{
thisTransform.position.x = Mathf.SmoothDamp (thisTransform.position.x, cameraTarget.transform.position.x + offset, velocity.x, smoothTime);
}
if (cameraFollowY) // if cameraFollowY = true = Inspector is checked
{
thisTransform.position.y = Mathf.SmoothDamp (thisTransform.position.y, cameraTarget.transform.position.y, velocity.y, smoothTime);
}
if (!cameraFollowY && cameraFollowHeight) // if cameraFollowY = false = Inspector is unchecked AND cameraFollowHeight = true = Inspector is checked
{
GetComponent.<Camera>().transform.position.y = cameraHeight; // The Camera Y position = cameraHeight
}
}
Comment
Answer by arbazgillani · Jul 21, 2016 at 05:48 AM
Use Smooth Follow Cam. The problem will be solved.