I'm making a game which involves rotating around a point shooting enemies before they reach said point, in 2D. However, as the enemies are going to be spawned in random places around the game, I need to make them rotate towards the centre to start moving in that direction. Here is the code that doesn't function properly:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public Rigidbody2D rb;
//this is the enemy, by the way
public Transform follow;
public void Start()
{
transform.LookAt(Vector2.zero);
rb.velocity = follow.up; //'up' worked in my bullet script for heading in the direction the player was facing
}
}
Instead of the knob rotating and slowly moving towards the point, the knob weirdly elongates and then begins to move towards the top of the screen, but at a slight angle. It's probably a stupid mistake, as I've only been writing in C# and using Unity for about a week.
However, any help would be greatly appreciated!