So hey guys!
i have this script which works fine
update() {
Vector3 point = camera.WorldToViewportPoint(new Vector3 (0f, 0f, 0f));
Vector3 delta = new Vector3 (originalPosition.x,target.position.y, 0f) - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(newVector3(0.5,0.5,point.z));
Vector3 destination = transform.position + delta ;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime) ;
}
but if i change it to fixedupdate the camera will follow the player up smoothly but choopy coming down
if i change it to lateupdate it will follow the player down smoothly but choppy going up
( i have tried update it doent do neither well )
the thing is gravity is bring the player down while a translate brings them up
how can i solve this to move booth directions smoothly
Hey there. Make sure to use Code Tags when posting snippets to the forum.
FixedUpdate is for physics operations. It doesn’t run every frame, only at a certain interval.
Would something like this work as a simple script on the camera? You can give it your player as the target.
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float speed;
private Vector3 velocity;
private void Update()
{
transform.position = Vector3.SmoothDamp(transform.position, target.position, ref velocity, speed);
}
}
You can also try setting your player’s rigidbody to interpolate to smooth out the movement between physics updates.
1 Like
i dont think that will cuz the player is constantly moving up and down i just want it to follow them up and down also i wanna limit the direction the camera goes
so if i go left or right it doesnt follow
but it will follow up and downs
rigidt body is set to extrapolate thou
How about this? You can check “lockX” and it wont move horizontally away from its starting location.
I don’t think you want Extrapolate, you’ll want Interpolate or none.
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float speed;
public bool lockX;
public bool lockY;
private Vector3 velocity;
private Vector3 startLocation;
private void Start()
{
startLocation = transform.position;
}
private void Update()
{
Vector3 targetPosition = target.position;
if(lockX)
{
targetPosition.x = startLocation.x;
}
if(lockY)
{
targetPosition.y = startLocation.y;
}
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, speed);
}
}
1 Like
well what i actually did was increase the damptime i had so it plays better to a pointnnnnnnnnnmkn