using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class camera : MonoBehaviour { public Transform FollowedObject; public Vector2 offset; private Vector2 dest; private Vector2 Vel; private Rigidbody2D RB; private Rigidbody2D FolRB; public Vector2 sus; public float Speed; private void Awake() { RB = this.gameObject.GetComponent(); FolRB = FollowedObject.GetComponent(); } void Update() { dest = FolRB.position + offset; Vel = RB.velocity; RB.velocity = (new Vector2(MathF.Round(dest.x*4, MidpointRounding.AwayFromZero)/4, MathF.Round(dest.y*4, MidpointRounding.AwayFromZero)/4) - RB.position)*Vector2.Distance(RB.position, FolRB.position)/Speed; } void FixedUpdate() { } }