- Home /
Question by
Rphysx · Apr 20, 2014 at 08:46 PM ·
backgroundfollowquad
Smooth Follow 2D simple tweak
I've applied this standard assets script to my camera and it's actually doing a good job but since my background texture is placed inside a quad that "follows" the player and not the camera at higher movement speed the camera gets too far or too much behind the player and gets out of view. Since I never programmed in JS I'd like to ask you how should I tweak this code to stop the script from moving the camera if the velocity is over (for example) 5f.
I tried to change it this way :
var target : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector2;
function Start()
{
thisTransform = transform;
}
function Update()
{
if(velocity.x > 5f) //in C# I'd do it this way, but apparently
velocity.x = 5f; //if velocity gets past 5, it doesn't remain 5
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, velocity.y, smoothTime);
}
Comment
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Equally Distributing Light On a Quad Object 2D 2 Answers
Background on a Quad 1 Answer
Background Image Distortion 2 Answers
Quad does not restart position 1 Answer