mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-27 03:34:17 +00:00
24 lines
693 B
C#
24 lines
693 B
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
[RequireComponent(typeof(Rigidbody2D))]
|
|||
|
public class MoveTowardsPlayer : MonoBehaviour
|
|||
|
{
|
|||
|
public float forceMultiplier = 3f;
|
|||
|
public float torqueMultiplier = 30f;
|
|||
|
|
|||
|
private new Rigidbody2D rigidbody2D;
|
|||
|
private GameObject player;
|
|||
|
|
|||
|
void Awake() {
|
|||
|
rigidbody2D = GetComponent<Rigidbody2D>();
|
|||
|
player = GameObject.FindGameObjectWithTag("Player");
|
|||
|
}
|
|||
|
|
|||
|
void Start() {
|
|||
|
rigidbody2D.AddForce((player.transform.position - transform.position).normalized * Random.value * forceMultiplier);
|
|||
|
rigidbody2D.AddTorque((Random.value - 0.5f) * 2f * torqueMultiplier);
|
|||
|
}
|
|||
|
}
|