basic rope whip attack

This commit is contained in:
Sveske Juice 2024-02-03 05:07:03 -08:00
parent d625572365
commit 49360ba4e8
8 changed files with 203 additions and 105 deletions

View File

@ -187,6 +187,7 @@ GameObject:
- component: {fileID: 1508323898269695585} - component: {fileID: 1508323898269695585}
- component: {fileID: 5467488512035376674} - component: {fileID: 5467488512035376674}
- component: {fileID: 3878447480781341932} - component: {fileID: 3878447480781341932}
- component: {fileID: 1749848915408613053}
m_Layer: 7 m_Layer: 7
m_Name: Player1 m_Name: Player1
m_TagString: Player m_TagString: Player
@ -223,10 +224,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3dbdb849a2f5df14d9e109a7776c5ac0, type: 3} m_Script: {fileID: 11500000, guid: 3dbdb849a2f5df14d9e109a7776c5ac0, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 5 player: 0
moveSpeed: 70
stepCooldown: 0.2 stepCooldown: 0.2
stepVibrationTime: 0.05 stepVibrationTime: 0.05
rumble: {fileID: 0} rumble: {fileID: 0}
whipAttack: {fileID: 1749848915408613053}
whipMoveSpeed: 25
maxWhipMoveSpeed: 30
--- !u!114 &3086165646112058191 --- !u!114 &3086165646112058191
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -261,7 +266,7 @@ Rigidbody2D:
m_UseFullKinematicContacts: 0 m_UseFullKinematicContacts: 0
m_UseAutoMass: 0 m_UseAutoMass: 0
m_Mass: 1 m_Mass: 1
m_LinearDrag: 0 m_LinearDrag: 10
m_AngularDrag: 0.05 m_AngularDrag: 0.05
m_GravityScale: 0 m_GravityScale: 0
m_Material: {fileID: 6200000, guid: 7c680ffb793a1f2478e6682c957e4868, type: 2} m_Material: {fileID: 6200000, guid: 7c680ffb793a1f2478e6682c957e4868, type: 2}
@ -302,3 +307,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9c2ddf673a65d3d49bc9470e1a4572e4, type: 3} m_Script: {fileID: 11500000, guid: 9c2ddf673a65d3d49bc9470e1a4572e4, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!114 &1749848915408613053
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3120938410244321186}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b69b92d72c7244443854899c4b700d9c, type: 3}
m_Name:
m_EditorClassIdentifier:
otherPlayerAttack: {fileID: 0}
playerMovement: {fileID: 651446758998956252}
joint: {fileID: 5467488512035376674}
initialDrag: 0

View File

@ -134,6 +134,7 @@ GameObject:
- component: {fileID: 63829549} - component: {fileID: 63829549}
- component: {fileID: 63829548} - component: {fileID: 63829548}
- component: {fileID: 63829547} - component: {fileID: 63829547}
- component: {fileID: 63829550}
m_Layer: 0 m_Layer: 0
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
@ -184,7 +185,7 @@ Camera:
far clip plane: 1000 far clip plane: 1000
field of view: 60 field of view: 60
orthographic: 1 orthographic: 1
orthographic size: 5 orthographic size: 16.46
m_Depth: -1 m_Depth: -1
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
@ -215,6 +216,50 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &63829550
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 63829546}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_AllowHDROutput: 1
m_UseScreenCoordOverride: 0
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
m_TaaSettings:
quality: 3
frameInfluence: 0.1
jitterScale: 1
mipBias: 0
varianceClampScale: 0.9
contrastAdaptiveSharpening: 0
--- !u!1 &99394924 --- !u!1 &99394924
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -678,6 +723,17 @@ MonoBehaviour:
serializedVersion: 2 serializedVersion: 2
m_Bits: 128 m_Bits: 128
inRange: 0 inRange: 0
--- !u!114 &465041015 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1749848915408613053, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
m_PrefabInstance: {fileID: 1273044612}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b69b92d72c7244443854899c4b700d9c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &625885767 --- !u!1 &625885767
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1391,38 +1447,28 @@ MonoBehaviour:
m_Area: 1 m_Area: 1
m_IgnoreFromBuild: 0 m_IgnoreFromBuild: 0
m_AffectedAgents: ffffffff m_AffectedAgents: ffffffff
--- !u!1 &1259212307 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3120938410244321186, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
m_PrefabInstance: {fileID: 1844950416}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1259212308 stripped --- !u!114 &1259212308 stripped
MonoBehaviour: MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5467488512035376674, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3} m_CorrespondingSourceObject: {fileID: 5467488512035376674, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
m_PrefabInstance: {fileID: 1844950416} m_PrefabInstance: {fileID: 1844950416}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1259212307} m_GameObject: {fileID: 0}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4aabce12c1341ff488ee4dc806fd80e8, type: 3} m_Script: {fileID: 11500000, guid: 4aabce12c1341ff488ee4dc806fd80e8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!114 &1259212311 --- !u!114 &1259212316 stripped
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 1749848915408613053, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 1844950416}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1259212307} m_GameObject: {fileID: 0}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e891644cda7544948af35b0d2f2c3be2, type: 3} m_Script: {fileID: 11500000, guid: b69b92d72c7244443854899c4b700d9c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 5
stepCooldown: 0.05
stepVibrationTime: 0.05
rumble: {fileID: 1744797149}
--- !u!1001 &1273044612 --- !u!1001 &1273044612
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1475,10 +1521,26 @@ PrefabInstance:
propertyPath: rumble propertyPath: rumble
value: value:
objectReference: {fileID: 1744797149} objectReference: {fileID: 1744797149}
- target: {fileID: 1749848915408613053, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 1259212316}
- target: {fileID: 3120938410244321186, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3} - target: {fileID: 3120938410244321186, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Player 1 value: Player 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3876439528830135059, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 0}
- target: {fileID: 5882735032023506905, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 0}
- target: {fileID: 7667011999606814046, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
@ -2221,22 +2283,38 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 651446758998956252, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: player
value: 1
objectReference: {fileID: 0}
- target: {fileID: 651446758998956252, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3} - target: {fileID: 651446758998956252, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: rumble propertyPath: rumble
value: value:
objectReference: {fileID: 1744797149} objectReference: {fileID: 1744797149}
- target: {fileID: 1749848915408613053, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 465041015}
- target: {fileID: 3120938410244321186, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3} - target: {fileID: 3120938410244321186, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Player 2 value: Player 2
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: - target: {fileID: 3876439528830135059, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
- {fileID: 651446758998956252, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3} propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 0}
- target: {fileID: 5882735032023506905, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 0}
- target: {fileID: 7667011999606814046, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
propertyPath: otherPlayerAttack
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: m_AddedComponents: []
- targetCorrespondingSourceObject: {fileID: 3120938410244321186, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
insertIndex: -1
addedObject: {fileID: 1259212311}
m_SourcePrefab: {fileID: 100100000, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 99a6ff8b9591949439b620b13bd249a4, type: 3}
--- !u!1660057539 &9223372036854775807 --- !u!1660057539 &9223372036854775807
SceneRoots: SceneRoots:

View File

@ -3,8 +3,9 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
public class PlayerMovement1 : MonoBehaviour public class PlayerMovement : MonoBehaviour
{ {
public int player = 0;
public float moveSpeed = 5f; public float moveSpeed = 5f;
private Rigidbody2D rb; private Rigidbody2D rb;
private Vector2 movement; private Vector2 movement;
@ -18,11 +19,21 @@ public class PlayerMovement1 : MonoBehaviour
[SerializeField] private GameObject rumble; [SerializeField] private GameObject rumble;
[Header("Whipping")]
[SerializeField]
RopeWhipAttack whipAttack;
[SerializeField]
private float whipMoveSpeed = 25f;
[SerializeField]
private float maxWhipMoveSpeed = 30f;
private void Start() private void Start()
{ {
rb = GetComponent<Rigidbody2D>(); rb = GetComponent<Rigidbody2D>();
playerController = Gamepad.all[0]; playerController = Gamepad.all[player];
StartCoroutine(ToggleWithDelay()); StartCoroutine(ToggleWithDelay());
} }
@ -44,7 +55,25 @@ public class PlayerMovement1 : MonoBehaviour
} }
private void FixedUpdate() private void FixedUpdate()
{ {
rb.velocity = (movement * moveSpeed); if (whipAttack.IsBeingWhipped)
{
float sign = movement.x > 0 ? 1 : -1;
if (movement.x == 0)
sign = 0;
Vector2 ropeDir = whipAttack.otherPlayerAttack.joint.position - whipAttack.joint.position;
Vector2 tangent = new Vector2(-ropeDir.y, ropeDir.x).normalized;
rb.AddForce(tangent * whipMoveSpeed * sign);
rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxWhipMoveSpeed);
}
else if (whipAttack.IsWhippingOtherPlayer)
{
movement = Vector2.zero;
}
else
{
rb.AddForce(movement * moveSpeed);
}
} }
private void RumbleWalk() private void RumbleWalk()
{ {

View File

@ -1,75 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement2 : MonoBehaviour
{
public float moveSpeed = 5f;
private Rigidbody2D rb;
private Vector2 movement;
private Gamepad playerController;
private bool right = false;
private bool vibrate = false;
[SerializeField] private float stepCooldown = 0.05f;
[SerializeField] private float stepVibrationTime = 0.05f;
[SerializeField] private GameObject rumble;
private float cooldown;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
playerController = Gamepad.all[1];
StartCoroutine(ToggleWithDelay());
}
void Update()
{
if (playerController != null)
{
movement.x = playerController.leftStick.x.ReadValue();
movement.y = playerController.leftStick.y.ReadValue();
}
else
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical"); ;
}
if (movement.x != 0 || movement.y != 0)
RumbleWalk();
}
private void FixedUpdate()
{
rb.velocity = (movement * moveSpeed);
}
private void RumbleWalk()
{
if (vibrate && playerController != null)
{
if (right)
{
rumble.GetComponent<RumbleManager>().RumblePulse2(0.0f, 0.004f, stepVibrationTime);
right = false;
}
else if (!right)
{
rumble.GetComponent<RumbleManager>().RumblePulse2(0.004f, 0.0f, stepVibrationTime);
right = true;
}
vibrate = false;
}
}
private IEnumerator ToggleWithDelay()
{
while (true)
{
vibrate = !vibrate;
yield return new WaitForSeconds(stepCooldown);
}
}
}

View File

@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class RopeWhipAttack : MonoBehaviour
{
public RopeWhipAttack otherPlayerAttack;
public PlayerMovement playerMovement;
public RopeJoint joint;
public bool IsWhippingOtherPlayer => joint.locked;
public bool IsBeingWhipped => otherPlayerAttack.joint.locked;
public float initialDrag;
private void Awake()
{
initialDrag = joint.body.drag;
}
private void Update()
{
// Other player is whip attacking
if (otherPlayerAttack.joint.locked) return;
if (Gamepad.all[playerMovement.player].rightShoulder.IsPressed())
{
joint.locked = true;
otherPlayerAttack.joint.body.drag = 0f;
}
else
{
joint.locked = false;
otherPlayerAttack.joint.body.drag = otherPlayerAttack.initialDrag;
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: e891644cda7544948af35b0d2f2c3be2 guid: b69b92d72c7244443854899c4b700d9c
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -142,12 +142,20 @@ public class RopeSimulator : MonoBehaviour
Vector2 force = pullDirection * overshoot * (pullForce / divider); Vector2 force = pullDirection * overshoot * (pullForce / divider);
start.body.AddForce(force); start.body.AddForce(force);
} }
else
{
start.body.velocity *= 0;
}
if (!end.locked) if (!end.locked)
{ {
Vector2 pullDirection = (rope.points[rope.points.Count - 2].position - end.position).normalized; Vector2 pullDirection = (rope.points[rope.points.Count - 2].position - end.position).normalized;
Vector2 force = pullDirection * overshoot * (pullForce / divider); Vector2 force = pullDirection * overshoot * (pullForce / divider);
end.body.AddForce(force); end.body.AddForce(force);
} }
else
{
end.body.velocity *= 0;
}
} }
// Handle squeze kills // Handle squeze kills
@ -285,7 +293,6 @@ public class RopeSimulator : MonoBehaviour
colliderToSquezeForce[hitCollider] = squezeForce + penetration.magnitude; colliderToSquezeForce[hitCollider] = squezeForce + penetration.magnitude;
p.position.Set(finalPos.x, finalPos.y, p.position.z); p.position.Set(finalPos.x, finalPos.y, p.position.z);
} }
} }