arm: {fileID: 8845918641001187994}
forceOrigin: {x: 0, y: 0.5, z: 0}
height: 0
+ isRoot: 0
+ isTop: 1
--- !u!50 &6095859832867562452
Rigidbody2D:
serializedVersion: 4
arm: {fileID: 61032117990659215}
forceOrigin: {x: 0, y: -0.5, z: 0}
height: 0
+ isRoot: 1
+ isTop: 0
--- !u!50 &6095859833589646292
Rigidbody2D:
serializedVersion: 4
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
+ - target: {fileID: 6267610020350316690, guid: 2485406c33a7d4f5481ce936cc9b162e, type: 3}
+ propertyPath: shotForce
+ value: 1000
+ objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2485406c33a7d4f5481ce936cc9b162e, type: 3}
--- !u!114 &707826158 stripped
objectReference: {fileID: 0}
- target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
propertyPath: sensitivity
- value: 2
+ value: 10
objectReference: {fileID: 0}
- target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
propertyPath: upSensitivity
objectReference: {fileID: 0}
- target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
propertyPath: verticalSensitivity
- value: 1.5
+ value: 7.5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
[SerializeField] private float maxLegAngle;
[SerializeField] private float legSpeed;
-
+
+ private void Awake()
+ {
+ foreach (var segment in segments) {
+ segment.sensitivity = sensitivity;
+ segment.verticalSensitivity = verticalSensitivity;
+ }
+ }
+
private void Update()
{
// Loop over each body segment and control it.
for (var i = 0; i < segments.Length; i++)
{
var segment = segments[i];
- var isRoot = i == 0;
- var isTop = i == segments.Length - 1;
// Update icons
foreach (var control in new[] {segment.left, segment.right})
}
// Add forces
- if (Input.GetKey(segment.left.keyCode))
- {
- segment.Rigidbody.AddForceAtPosition(
- Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) +
- Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
- segment.transform.position + (segment.height * segment.forceOrigin));
- }
-
- if (Input.GetKey(segment.right.keyCode))
- {
- segment.Rigidbody.AddForceAtPosition(
- Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) +
- Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
- segment.transform.position + (segment.height * segment.forceOrigin));
- }
+ segment.moveleft = Input.GetKey(segment.left.keyCode);
+ segment.moveright = Input.GetKey(segment.right.keyCode);
// Rotate the legs if we move.
- if (isRoot)
+ if (segment.isRoot)
{
if (Input.GetKey(segment.left.keyCode) || Input.GetKey(segment.right.keyCode))
{
}
}
- if (isTop)
+ if (segment.isTop)
{
game.player.Move(segment.transform.position);
[RequireComponent(typeof(Rigidbody2D))]
public class PlayerSegment : MonoBehaviour
{
+ internal float sensitivity;
+ internal float verticalSensitivity;
+
+ internal bool moveleft;
+ internal bool moveright;
+
[SerializeField] public Control left;
[SerializeField] public Control right;
[SerializeField] public Vector3 forceOrigin;
[SerializeField] public float height;
+ [SerializeField] public bool isRoot;
+ [SerializeField] public bool isTop;
public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
private Rigidbody2D _rigidbody;
+
+ private void FixedUpdate()
+ {
+ if (moveleft)
+ {
+ Rigidbody.AddForceAtPosition(
+ Vector2.left * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
+ transform.position + (height * forceOrigin));
+ }
+ if (moveright)
+ {
+ Rigidbody.AddForceAtPosition(
+ Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) + Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
+ transform.position + (height * forceOrigin));
+ }
+ }
}
[Serializable]