using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateAroundTarget : MonoBehaviour
{
public Transform target;
public float speed;
public Vector3 axis;
public DrawCircle dc;
private float lastRadius;
private bool move = false;
private void Start()
{
lastRadius = dc.xRadius;
move = true;
}
private void Update()
{
Vector3 radiusPosition = new Vector3(target.position.x, target.position.y, dc.xRadius);
if (transform.position == radiusPosition)
{
transform.RotateAround(target.position, axis, speed * Time.deltaTime);
}
if (lastRadius != dc.xRadius)
{
move = true;
lastRadius = dc.xRadius;
}
if(move)
{
if (transform.position != radiusPosition)
{
float step = 1 * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position,
radiusPosition, step);
}
}
}
}
The transform is moving towards the radius position and then should start rotating on the radius.
The problem is that after the transform is reaching the radius position and for example the transform position and the radius position is the same and true :
In this case the position of the transform and the radiusPosition is "(0.0, 0.0, 2.0)" and the condition is true but still it's getting inside and changing the transform position.
So it's not moving between the lines :
transform.RotateAround(target.position, axis, speed * Time.deltaTime);
And
float step = 1 * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position,
radiusPosition, step);
I can't figure out why.
What i'm trying to archive is to make the transform to move on the start towards the radius and then to start rotating around on the radius. but for some reason the IF conditions are not working as expected.
The transform is rotating around it self and shaking like it's trying to move/rotatearound but never rotate around.

