You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RatAttack2D/Assets/Scripts/camera.cs

24 lines
727 B

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camera : MonoBehaviour
{
public Rigidbody2D FollowedObject;
public Vector2 offset;
private Vector2 dest;
private Vector2 Vel;
private Rigidbody2D RB;
public float Speed;
private void Awake()
{
RB = this.gameObject.GetComponent<Rigidbody2D>();
}
void Update()
{
dest = FollowedObject.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, FollowedObject.position)/Speed;
}
}