So iam trying to move the camera down when player is falling so, the player is constantly in view of camera.
https://giant.gfycat.com/GiganticFeistyIlladopsis.webm
Iam trying to do it by chaning delta.y to positive by “delta.y = -delta.y” so, in theory if playing is falling and camera is behind trailing the player the delta.y vector is decresing going like -0.5 > -1 > -1.5 > -2 > …
So if I change this value to " delta = -delta " its should go like 0.5 > 1 > 1.5 > 2 > … but it doesnt work. Well it doesnt work as it is supposed to be working, insted going like 0.5 > 1 > 1.5 > 2 >… it doubles the noumbers but they are still negative(i want the numbers positive) -1 > -1.5 > -2.0 > -2.5 > …
using UnityEngine;
using System.Collections;
public class SmoothCamera2D : MonoBehaviour {
public float dampTime = 0.15f;
private Vector3 velocity = Vector3.zero;
public Transform target;
// Update is called once per frame
void Update ()
{
if (target)
{
Vector3 point = camera.WorldToViewportPoint(target.position);
Vector3 delta = target.position - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
if (target.GetComponent<playerCtonroller>().isJumping)
{
if(target.GetComponent<Rigidbody2D>().velocity.y <= 0)
{
delta.y = -delta.y;
}
}
Vector3 destination = transform.position + delta;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
}
}
}