I’m trying to rotate an enemy around the player object, but when I do this the enemy sprite itself rotates around.
I want to freeze its rotation, or perhaps rotate itself backwards to compensate? What’s the solution here?
Here’s what I have so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySeagull : MonoBehaviour
{
public float moveSpeed;
public float orbitDistance;
public float rangeToAnnoyPlayer;
private Transform target;
private bool isInRange;
private Vector3 zAxis = new Vector3(0,0,1);
// Start is called before the first frame update
void Start()
{
isInRange = false;
target = PlayerController.instance.transform;
}
// Update is called once per frame
void Update()
{
if (!isInRange)
{
if (Vector2.Distance(transform.position, PlayerController.instance.transform.position) < rangeToAnnoyPlayer)
{
isInRange = true;
}
}
if (isInRange)
{
transform.position = target.position + (transform.position - target.position).normalized * orbitDistance;
transform.RotateAround(PlayerController.instance.transform.position, zAxis, 120 * Time.deltaTime);
}
else
{
transform.position = Vector3.MoveTowards(transform.position, target.position, 3 * Time.deltaTime);
}
Debug.Log("isInRange = " + isInRange);
}
}