rebuild rope on shrink extend WIP
This commit is contained in:
parent
b2e26ce8d2
commit
e1a44344fe
|
@ -868,6 +868,7 @@ MonoBehaviour:
|
||||||
anchor: {fileID: 625885769}
|
anchor: {fileID: 625885769}
|
||||||
body: {fileID: 0}
|
body: {fileID: 0}
|
||||||
locked: 0
|
locked: 0
|
||||||
|
playerInput: {fileID: 0}
|
||||||
--- !u!1 &646449334
|
--- !u!1 &646449334
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -1103,17 +1104,6 @@ MonoBehaviour:
|
||||||
m_Area: 0
|
m_Area: 0
|
||||||
m_IgnoreFromBuild: 0
|
m_IgnoreFromBuild: 0
|
||||||
m_AffectedAgents: ffffffff
|
m_AffectedAgents: ffffffff
|
||||||
--- !u!114 &1081435768 stripped
|
|
||||||
MonoBehaviour:
|
|
||||||
m_CorrespondingSourceObject: {fileID: 1949941092232239315, 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: de340bb967770a7499e140a52a287f84, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
--- !u!1 &1156361827
|
--- !u!1 &1156361827
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -2075,7 +2065,6 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 27ac133d9e10e544ba603e07122e3359, type: 3}
|
m_Script: {fileID: 11500000, guid: 27ac133d9e10e544ba603e07122e3359, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
playerInput: {fileID: 1081435768}
|
|
||||||
gravity: 15
|
gravity: 15
|
||||||
solveIterations: 10
|
solveIterations: 10
|
||||||
constrainStickMinLength: 0
|
constrainStickMinLength: 0
|
||||||
|
@ -2092,6 +2081,9 @@ MonoBehaviour:
|
||||||
m_Bits: 1
|
m_Bits: 1
|
||||||
pullForce: 65
|
pullForce: 65
|
||||||
xyGravityDampScalor: 1
|
xyGravityDampScalor: 1
|
||||||
|
ropeExtendSpeed: 15
|
||||||
|
ropeShrinkSpeed: 15
|
||||||
|
ropeMaxLength: 0
|
||||||
lineRenderer: {fileID: 1647138191}
|
lineRenderer: {fileID: 1647138191}
|
||||||
--- !u!4 &1647138193
|
--- !u!4 &1647138193
|
||||||
Transform:
|
Transform:
|
||||||
|
|
|
@ -10,11 +10,12 @@ public class PlayerInput : MonoBehaviour
|
||||||
[SerializeField] private int playerNumber;
|
[SerializeField] private int playerNumber;
|
||||||
|
|
||||||
public Vector2 movement;
|
public Vector2 movement;
|
||||||
|
public Vector2 look;
|
||||||
public Gamepad controller { get; private set; }
|
public Gamepad controller { get; private set; }
|
||||||
|
|
||||||
public bool whipAttack;
|
public bool whipAttack;
|
||||||
public event Action ropeLengthShrinken;
|
public event Action<int> ropeLengthShrinken;
|
||||||
public event Action ropeLengthExtend;
|
public event Action<int> ropeLengthExtend;
|
||||||
|
|
||||||
public int PlayerNum => playerNumber;
|
public int PlayerNum => playerNumber;
|
||||||
|
|
||||||
|
@ -34,10 +35,13 @@ public class PlayerInput : MonoBehaviour
|
||||||
movement.x = controller.leftStick.x.ReadValue();
|
movement.x = controller.leftStick.x.ReadValue();
|
||||||
movement.y = controller.leftStick.y.ReadValue();
|
movement.y = controller.leftStick.y.ReadValue();
|
||||||
|
|
||||||
|
look.x = controller.rightStick.x.ReadValue();
|
||||||
|
look.y = controller.rightStick.y.ReadValue();
|
||||||
|
|
||||||
whipAttack = controller.buttonWest.IsPressed();
|
whipAttack = controller.buttonWest.IsPressed();
|
||||||
|
|
||||||
if (controller.rightShoulder.IsPressed()) ropeLengthShrinken?.Invoke();
|
if (controller.rightShoulder.IsPressed()) ropeLengthShrinken?.Invoke(playerNumber);
|
||||||
if (controller.leftShoulder.IsPressed()) ropeLengthExtend?.Invoke();
|
if (controller.leftShoulder.IsPressed()) ropeLengthExtend?.Invoke(playerNumber);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,13 @@ public class RopeBuilder
|
||||||
List<Point> points = new();
|
List<Point> points = new();
|
||||||
List<Stick> sticks = new();
|
List<Stick> sticks = new();
|
||||||
|
|
||||||
|
public RopeBuilder() { }
|
||||||
|
public RopeBuilder(List<Point> points, List<Stick> sticks)
|
||||||
|
{
|
||||||
|
this.points = points;
|
||||||
|
this.sticks = sticks;
|
||||||
|
}
|
||||||
|
|
||||||
public RopeBuilder AddPoint(Point point)
|
public RopeBuilder AddPoint(Point point)
|
||||||
{
|
{
|
||||||
points.Add(point);
|
points.Add(point);
|
||||||
|
|
|
@ -50,11 +50,11 @@ public class RopeSimulator : MonoBehaviour
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
float xyGravityDampScalor = 1f;
|
float xyGravityDampScalor = 1f;
|
||||||
|
|
||||||
[SerializeField, Range(0f, 5f)]
|
[SerializeField, Range(0f, 20f)]
|
||||||
public float ropeExtendSpeed, ropeShrinkSpeed;
|
public float ropeExtendSpeed, ropeShrinkSpeed;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public float ropeMaxLength;
|
public float ropeMaxLength, ropeMinLength;
|
||||||
|
|
||||||
[Header("Rendering")]
|
[Header("Rendering")]
|
||||||
[SerializeField] LineRenderer lineRenderer;
|
[SerializeField] LineRenderer lineRenderer;
|
||||||
|
@ -87,15 +87,54 @@ public class RopeSimulator : MonoBehaviour
|
||||||
end.playerInput.ropeLengthExtend += ExtendRope;
|
end.playerInput.ropeLengthExtend += ExtendRope;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShrinkenRope()
|
void ShrinkenRope(int playerNumber)
|
||||||
{
|
{
|
||||||
subDivision += ropeShrinkSpeed * Time.deltaTime;
|
int prevSubDivision = (int) subDivision;
|
||||||
Rebuild();
|
subDivision -= ropeShrinkSpeed * Time.deltaTime;
|
||||||
|
if (subDivision < ropeMinLength)
|
||||||
|
subDivision = ropeMinLength;
|
||||||
|
|
||||||
|
if (prevSubDivision - (int)subDivision > 0) return;
|
||||||
|
|
||||||
|
// Shrink from start
|
||||||
|
if (playerNumber == start.playerInput.PlayerNum)
|
||||||
|
{
|
||||||
|
rope.sticks.Clear();
|
||||||
|
rope.points.RemoveAt(0);
|
||||||
|
|
||||||
|
var builder = new RopeBuilder(rope.points, new List<Stick>());
|
||||||
|
|
||||||
|
// Re-gen sticks
|
||||||
|
for (int i = 0; i < (int) subDivision; i++)
|
||||||
|
{
|
||||||
|
builder.ConnectPoints(i, i + 1);
|
||||||
|
}
|
||||||
|
rope = builder.Build();
|
||||||
|
}
|
||||||
|
// Shrink from end
|
||||||
|
else if (playerNumber == end.playerInput.PlayerNum)
|
||||||
|
{
|
||||||
|
rope.points.RemoveAt(rope.points.Count - 2);
|
||||||
|
rope.sticks.Clear();
|
||||||
|
|
||||||
|
var builder = new RopeBuilder(rope.points, new List<Stick>());
|
||||||
|
|
||||||
|
// Re-gen sticks
|
||||||
|
for (int i = 0; i < (int)subDivision; i++)
|
||||||
|
{
|
||||||
|
builder.ConnectPoints(i, i + 1);
|
||||||
|
}
|
||||||
|
rope = builder.Build();
|
||||||
|
}
|
||||||
|
CreateOrderArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtendRope()
|
void ExtendRope(int playerNumber)
|
||||||
{
|
{
|
||||||
subDivision -= ropeExtendSpeed * Time.deltaTime;
|
subDivision += ropeExtendSpeed * Time.deltaTime;
|
||||||
|
if (subDivision > ropeMaxLength)
|
||||||
|
subDivision = ropeMaxLength;
|
||||||
|
|
||||||
Rebuild();
|
Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +189,7 @@ public class RopeSimulator : MonoBehaviour
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
ShrinkenRope(1);
|
||||||
colliderToSquezeForce.Clear();
|
colliderToSquezeForce.Clear();
|
||||||
|
|
||||||
rope.points.First().position = start.position;
|
rope.points.First().position = start.position;
|
||||||
|
|
Loading…
Reference in New Issue