Aiming system done

This commit is contained in:
Sveske Juice 2024-04-20 18:12:49 +02:00
parent 6806df3fed
commit 0e717ffa28
3 changed files with 18 additions and 15 deletions

View File

@ -152,8 +152,7 @@ MonoBehaviour:
samples: 25
visualRadius: 1
knob: {fileID: 8756968480882234867}
knobSensitiviy: 1
moveKnobAxisName: Mouse X
knobSensitiviy: 4
rotationMinMax: {x: 0, y: 360}
--- !u!1 &2485007193584062128
GameObject:
@ -576,9 +575,8 @@ MonoBehaviour:
samples: 15
visualRadius: 1
knob: {fileID: 1398471167256814047}
knobSensitiviy: 1
moveKnobAxisName: Mouse Y
rotationMinMax: {x: -30, y: 30}
knobSensitiviy: 4
rotationMinMax: {x: 0, y: 360}
--- !u!1 &8708866392971799934
GameObject:
m_ObjectHideFlags: 0

View File

@ -84,6 +84,7 @@ public class ProjectileTower : Tower
// Rotate barrel to match rotation
private void UpdateBarrelRotation()
{
barrel.transform.localRotation = Quaternion.Euler(verticalArc.Value, horizontalArc.Value, 0f);
// TODOu
barrel.transform.localRotation = Quaternion.Euler(-verticalArc.Value, horizontalArc.Value, 0f);
}
}

View File

@ -16,7 +16,6 @@ public class EditableArc : MonoBehaviour
[SerializeField] private float visualRadius = 1f;
[SerializeField] private SliderKnob knob;
[SerializeField] private float knobSensitiviy = 1f;
[SerializeField] private string moveKnobAxisName = "Mouse X";
[SerializeField] private Vector2 rotationMinMax = new Vector2(-30f, 30f);
private LineRenderer lineRenderer;
@ -69,17 +68,22 @@ public class EditableArc : MonoBehaviour
Vector3 start = Quaternion.AngleAxis(rotationMinMax.x, normal) * tangent;
Vector3 end = Quaternion.AngleAxis(rotationMinMax.y, normal) * tangent;
// Use calculus to calculate differentialkvotient tangent at angle
Vector3 v1 = SamplePointOnArcAngle(start, end, visualRadius, Value.Value);
Vector3 v2 = SamplePointOnArcAngle(start, end, visualRadius, Value.Value + 1f);
Vector3 arcTangent = (v2 - v1).normalized;
Debug.DrawRay(knob.transform.position, arcTangent, Color.yellow, 5f);
Debug.Log($"tangent: {arcTangent}");
Vector3 v2 = SamplePointOnArcAngle(start, end, visualRadius, Value.Value - 1f);
Vector3 arcTangent3D = (v2 - v1).normalized;
Vector2 arcTangent = orientation == ArcOrientation.HORIZONTAL ? new Vector2(arcTangent3D.x, arcTangent3D.z) : new Vector2(arcTangent3D.x, arcTangent3D.y);
// TODO: figure out this based on camera orientation
float sign = -1f;
// i have no idea why but somehow this needs to be here idk
if (orientation == ArcOrientation.VERTICAL)
arcTangent.x *= -1f;
Debug.DrawRay(knob.transform.position, arcTangent3D, Color.yellow, 5f);
float sign = orientation == ArcOrientation.HORIZONTAL ? 1f : -1f;
float delta = Vector2.Dot(arcTangent, mouseMovement) * knobSensitiviy * sign;
float delta = (Vector2.Dot(arcTangent, Vector2.up * mouseMovement.x) + Vector2.Dot(arcTangent, Vector2.right * mouseMovement.y)) * knobSensitiviy * sign;
Debug.Log(delta);
float newAngle = ClampAngle(Value.Value + delta, rotationMinMax.x, rotationMinMax.y);
Value.Value = newAngle;
}