I set in the inspector the radius value to 0.1 but when it’s rotating around the player character it looks like the radius is bigger then. 0.1
radius 0.1 meaning the Sphere should almost touching if not touching the player. but in the screenshots, it looks too far for a 0.1 radius distance.
the first screenshot is when the Sphere child scaling is set to 0.1, 0.1, 0.1 and the second screenshot is when i tried to set the Sphere child scaling to 1,1,1 in both cases it looks too far for 0.1 radius.
and the script that is attached to the empty GameObject.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateAroundPoint : MonoBehaviour
{
[Header("Target")]
public UnityEngine.Transform target;
[Header("Rotating Speed")]
public float rotatingSpeed;
[Header("First Move To Radius Settings")]
public float movingToRadiusSpeed;
public bool moveToRadius = false;
[Header("Axis Settings")]
public Vector3 axis;
[Header("Height Settings")]
public bool randomHeight;
public float upperLimit, lowerLimit;
public float setRandomHeight = 1;
public float delay;
[Header("Radius Settings")]
public float radius;
[Header("Reference To DrawCircle Script")]
public DrawCircle dc;
[Header("Reference To Linerenderer")]
public LineRenderer lineRenderer;
private float lastRadius;
private float t = 0.0f;
private float prevHeight;
private Vector3 radiusPosition;
private Vector3[] positions;
private void Start()
{
if (dc != null)
{
lastRadius = dc.xRadius;
radius = dc.xRadius;
}
else
{
lastRadius = radius;
}
if (lineRenderer != null)
{
GetLinePointsInWorldSpace();
}
}
private void Update()
{
if (target != null)
{
if (dc != null)
{
radiusPosition = new Vector3(target.position.x,
target.position.y + dc.yRadius, target.position.z + dc.xRadius);
radius = dc.xRadius;
}
else
{
radiusPosition = new Vector3(target.position.x, target.position.y, target.position.z + radius);
}
}
if (moveToRadius == false)
{
if (target != null)
{
transform.RotateAround(target.position, axis, rotatingSpeed * Time.deltaTime);
}
if (randomHeight)
{
t += Time.deltaTime;
if (t > delay)
{
prevHeight = setRandomHeight;
setRandomHeight = Random.Range(lowerLimit, upperLimit);
t = 0;
}
var tt = transform.position;
tt.y = Mathf.Lerp(prevHeight, setRandomHeight, t);
transform.position = tt;
}
}
if (dc != null)
{
if (lastRadius != dc.xRadius)
{
moveToRadius = true;
lastRadius = dc.xRadius;
}
}
else
{
if (lastRadius != radius)
{
moveToRadius = true;
lastRadius = radius;
}
}
if (moveToRadius)
{
if (transform.position != radiusPosition)
{
transform.position = Vector3.MoveTowards(transform.position,
radiusPosition, movingToRadiusSpeed * Time.deltaTime);
}
else
{
moveToRadius = false;
}
}
}
Vector3[] GetLinePointsInWorldSpace()
{
positions = new Vector3[lineRenderer.positionCount];
//Get the positions which are shown in the inspector
lineRenderer.GetPositions(positions);
//the points returned are in world space
return positions;
}
}