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

31 lines
865 B

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<Rigidbody2D>();
FolRB = FollowedObject.GetComponent<Rigidbody2D>();
}
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()
{
}
}