Support 360 aim

This commit is contained in:
Sveske Juice 2024-04-20 16:49:40 +02:00
parent 4e68e8bd46
commit 5d0152f823
3 changed files with 29 additions and 5 deletions

View File

@ -149,12 +149,12 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
orientation: 0 orientation: 0
samples: 15 samples: 25
visualRadius: 1 visualRadius: 1
knob: {fileID: 8756968480882234867} knob: {fileID: 8756968480882234867}
knobSensitiviy: 1 knobSensitiviy: 1
moveKnobAxisName: Mouse X moveKnobAxisName: Mouse X
rotationMinMax: {x: -30, y: 30} rotationMinMax: {x: 0, y: 360}
--- !u!1 &2485007193584062128 --- !u!1 &2485007193584062128
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -650,6 +650,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Turret value: Turret
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8981486734084153558, guid: 9415cb10a1bd579269301ca4f61a1554,
type: 3}
propertyPath: rotationMinMax.y
value: 360
objectReference: {fileID: 0}
- target: {fileID: 9116936080776508834, guid: 9415cb10a1bd579269301ca4f61a1554, - target: {fileID: 9116936080776508834, guid: 9415cb10a1bd579269301ca4f61a1554,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x

View File

@ -37,7 +37,7 @@ public class EditableArc : MonoBehaviour
Value.AddListener(UpdateKnobPosition); Value.AddListener(UpdateKnobPosition);
// Set default rotation to average between min max // Set default rotation to average between min max
Value.Value = (rotationMinMax.x + rotationMinMax.y) / 2f; // Value.Value = (rotationMinMax.x + rotationMinMax.y) / 2f;
Assert.IsNotNull(knob, $"No knob on {this}"); Assert.IsNotNull(knob, $"No knob on {this}");
knob.OnDrag += PointerDraggedOnKnob; knob.OnDrag += PointerDraggedOnKnob;
@ -71,7 +71,7 @@ public class EditableArc : MonoBehaviour
float sign = -1f; float sign = -1f;
float delta = mouseMovement * knobSensitiviy * sign; float delta = mouseMovement * knobSensitiviy * sign;
float newAngle = Mathf.Clamp(Value.Value + delta, rotationMinMax.x, rotationMinMax.y); float newAngle = ClampAngle(Value.Value + delta, rotationMinMax.x, rotationMinMax.y);
Value.Value = newAngle; Value.Value = newAngle;
} }
@ -100,12 +100,31 @@ public class EditableArc : MonoBehaviour
} }
lineRenderer.SetPositions(positions); lineRenderer.SetPositions(positions);
// Set looop
Debug.Log(angle);
if (angle >= 360)
lineRenderer.loop = true;
else
lineRenderer.loop = false;
} }
public Vector3 SamplePointOnArc(Vector3 startPoint, Vector3 endPoint, float radius, float t) public Vector3 SamplePointOnArc(Vector3 startPoint, Vector3 endPoint, float radius, float t)
{ {
float angle = Mathf.LerpAngle(rotationMinMax.x, rotationMinMax.y, t); float angle = Mathf.Lerp(rotationMinMax.x, rotationMinMax.y, t);
Vector3 dir = Quaternion.AngleAxis(angle, normal) * tangent; Vector3 dir = Quaternion.AngleAxis(angle, normal) * tangent;
return transform.position + dir.normalized * radius; return transform.position + dir.normalized * radius;
} }
public static float ClampAngle(float current, float min, float max)
{
float dtAngle = Mathf.Abs(((min - max) + 180) % 360 - 180);
float hdtAngle = dtAngle * 0.5f;
float midAngle = min + hdtAngle;
float offset = Mathf.Abs(Mathf.DeltaAngle(current, midAngle)) - hdtAngle;
if (offset > 0)
current = Mathf.MoveTowardsAngle(current, midAngle, offset);
return current;
}
} }