left:
keyCode: 276
icon: {fileID: 5020703169596630212}
+ leg: {fileID: 414971659141114100}
+ arm: {fileID: 8549221634172624537}
right:
keyCode: 275
icon: {fileID: 476429766403681147}
+ leg: {fileID: 5886521033835613979}
+ arm: {fileID: 8845918641001187994}
forceOrigin: {x: 0, y: 0.5, z: 0}
height: 0
--- !u!50 &6095859832867562452
left:
keyCode: 97
icon: {fileID: 5321565721314628342}
+ leg: {fileID: 2835159121523199489}
+ arm: {fileID: 6791963013674012835}
right:
keyCode: 100
icon: {fileID: 7797841368364398355}
+ leg: {fileID: 3531439111263992317}
+ arm: {fileID: 61032117990659215}
forceOrigin: {x: 0, y: -0.5, z: 0}
height: 0
--- !u!50 &6095859833589646292
controls:
grab: 119
shoot: 273
+ maxLegAngle: 30
+ legSpeed: 10
--- !u!1 &6791963013674012835
GameObject:
m_ObjectHideFlags: 0
propertyPath: game
value:
objectReference: {fileID: 1174357920}
+ - target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
+ propertyPath: legSpeed
+ value: 5
+ objectReference: {fileID: 0}
- target: {fileID: 6095859834264611326, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3}
propertyPath: sensitivity
value: 2
[SerializeField] private GameController game;
[SerializeField] private Controls controls;
+
+ [SerializeField] private float maxLegAngle;
+ [SerializeField] private float legSpeed;
private void Update()
{
// 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));
+ {
+ 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.Rigidbody.AddForceAtPosition(
+ Vector2.right * (sensitivity * (isRoot ? 2f : 1f)) +
+ Vector2.up * (verticalSensitivity * (isRoot ? -1f : 1f)),
+ segment.transform.position + (segment.height * segment.forceOrigin));
+ }
+
+ // Rotate the legs if we move.
+ if (isRoot)
+ {
+ if (Input.GetKey(segment.left.keyCode) || Input.GetKey(segment.right.keyCode))
+ {
+ segment.left.leg.transform.localRotation =
+ Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * legSpeed));
+ segment.right.leg.transform.localRotation =
+ Quaternion.Euler(0, 0, maxLegAngle * Mathf.Sin(Time.time * -legSpeed));
+ }
+ else
+ {
+ segment.left.leg.transform.localRotation = Quaternion.Slerp(segment.left.leg.transform.localRotation, Quaternion.identity, Time.deltaTime * legSpeed);
+ segment.right.leg.transform.localRotation = Quaternion.Slerp(segment.right.leg.transform.localRotation, Quaternion.identity, Time.deltaTime * legSpeed);
+ }
+ }
if (isTop)
+ {
game.player.Move(segment.transform.position);
+
+ // Point the arms at the ball.
+ segment.left.arm.transform.up = -(game.ball.transform.position - segment.left.arm.transform.position);
+ segment.right.arm.transform.up = -(game.ball.transform.position - segment.right.arm.transform.position);
+ }
}
// Try grabbing the ball if pressed.