Aiming system done
This commit is contained in:
parent
6806df3fed
commit
0e717ffa28
|
@ -152,8 +152,7 @@ MonoBehaviour:
|
||||||
samples: 25
|
samples: 25
|
||||||
visualRadius: 1
|
visualRadius: 1
|
||||||
knob: {fileID: 8756968480882234867}
|
knob: {fileID: 8756968480882234867}
|
||||||
knobSensitiviy: 1
|
knobSensitiviy: 4
|
||||||
moveKnobAxisName: Mouse X
|
|
||||||
rotationMinMax: {x: 0, y: 360}
|
rotationMinMax: {x: 0, y: 360}
|
||||||
--- !u!1 &2485007193584062128
|
--- !u!1 &2485007193584062128
|
||||||
GameObject:
|
GameObject:
|
||||||
|
@ -576,9 +575,8 @@ MonoBehaviour:
|
||||||
samples: 15
|
samples: 15
|
||||||
visualRadius: 1
|
visualRadius: 1
|
||||||
knob: {fileID: 1398471167256814047}
|
knob: {fileID: 1398471167256814047}
|
||||||
knobSensitiviy: 1
|
knobSensitiviy: 4
|
||||||
moveKnobAxisName: Mouse Y
|
rotationMinMax: {x: 0, y: 360}
|
||||||
rotationMinMax: {x: -30, y: 30}
|
|
||||||
--- !u!1 &8708866392971799934
|
--- !u!1 &8708866392971799934
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class ProjectileTower : Tower
|
||||||
// Rotate barrel to match rotation
|
// Rotate barrel to match rotation
|
||||||
private void UpdateBarrelRotation()
|
private void UpdateBarrelRotation()
|
||||||
{
|
{
|
||||||
barrel.transform.localRotation = Quaternion.Euler(verticalArc.Value, horizontalArc.Value, 0f);
|
// TODOu
|
||||||
|
barrel.transform.localRotation = Quaternion.Euler(-verticalArc.Value, horizontalArc.Value, 0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ public class EditableArc : MonoBehaviour
|
||||||
[SerializeField] private float visualRadius = 1f;
|
[SerializeField] private float visualRadius = 1f;
|
||||||
[SerializeField] private SliderKnob knob;
|
[SerializeField] private SliderKnob knob;
|
||||||
[SerializeField] private float knobSensitiviy = 1f;
|
[SerializeField] private float knobSensitiviy = 1f;
|
||||||
[SerializeField] private string moveKnobAxisName = "Mouse X";
|
|
||||||
|
|
||||||
[SerializeField] private Vector2 rotationMinMax = new Vector2(-30f, 30f);
|
[SerializeField] private Vector2 rotationMinMax = new Vector2(-30f, 30f);
|
||||||
private LineRenderer lineRenderer;
|
private LineRenderer lineRenderer;
|
||||||
|
@ -69,17 +68,22 @@ public class EditableArc : MonoBehaviour
|
||||||
|
|
||||||
Vector3 start = Quaternion.AngleAxis(rotationMinMax.x, normal) * tangent;
|
Vector3 start = Quaternion.AngleAxis(rotationMinMax.x, normal) * tangent;
|
||||||
Vector3 end = Quaternion.AngleAxis(rotationMinMax.y, 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 v1 = SamplePointOnArcAngle(start, end, visualRadius, Value.Value);
|
||||||
Vector3 v2 = SamplePointOnArcAngle(start, end, visualRadius, Value.Value + 1f);
|
Vector3 v2 = SamplePointOnArcAngle(start, end, visualRadius, Value.Value - 1f);
|
||||||
Vector3 arcTangent = (v2 - v1).normalized;
|
Vector3 arcTangent3D = (v2 - v1).normalized;
|
||||||
Debug.DrawRay(knob.transform.position, arcTangent, Color.yellow, 5f);
|
Vector2 arcTangent = orientation == ArcOrientation.HORIZONTAL ? new Vector2(arcTangent3D.x, arcTangent3D.z) : new Vector2(arcTangent3D.x, arcTangent3D.y);
|
||||||
Debug.Log($"tangent: {arcTangent}");
|
|
||||||
|
|
||||||
// TODO: figure out this based on camera orientation
|
// i have no idea why but somehow this needs to be here idk
|
||||||
float sign = -1f;
|
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);
|
float newAngle = ClampAngle(Value.Value + delta, rotationMinMax.x, rotationMinMax.y);
|
||||||
Value.Value = newAngle;
|
Value.Value = newAngle;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue