ok maybe just single jump

master
Jordan Orelli 4 years ago
parent 5e5c24da33
commit c33c94990c

@ -7471,7 +7471,7 @@ PrefabInstance:
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662, - target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3} type: 3}
propertyPath: timeToJumpApex propertyPath: timeToJumpApex
value: 0.3 value: 0.25
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662, - target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3} type: 3}
@ -7491,7 +7491,7 @@ PrefabInstance:
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662, - target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3} type: 3}
propertyPath: maxFallSpeed propertyPath: maxFallSpeed
value: -30 value: -40
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662, - target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3} type: 3}
@ -7513,5 +7513,10 @@ PrefabInstance:
propertyPath: timeToMaxAirmoveSpeed propertyPath: timeToMaxAirmoveSpeed
value: 0.25 value: 0.25
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: maxJumps
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b29a944aaba25f643afdc6b049845662, type: 3} m_SourcePrefab: {fileID: 100100000, guid: b29a944aaba25f643afdc6b049845662, type: 3}

@ -14,6 +14,7 @@ public class PlayerController : MonoBehaviour {
public float timeToMaxAirmoveSpeed = 0.025f; public float timeToMaxAirmoveSpeed = 0.025f;
public float maxApexTime = 0.05f; // amount of time spent at max jump height before falling again public float maxApexTime = 0.05f; // amount of time spent at max jump height before falling again
public float coyoteTime = 0.1f; public float coyoteTime = 0.1f;
public int maxJumps = 2;
public GameObject tracerPrefab; public GameObject tracerPrefab;
// this has to be public to be readable by the display, which is a code // this has to be public to be readable by the display, which is a code
@ -23,6 +24,7 @@ public class PlayerController : MonoBehaviour {
private float jumpStateStart; private float jumpStateStart;
private float jumpStartTime; private float jumpStartTime;
private float jumpHeldDuration; private float jumpHeldDuration;
public int jumpCount;
private bool wasHoldingJump; private bool wasHoldingJump;
public float apexTime; public float apexTime;
@ -73,6 +75,7 @@ public class PlayerController : MonoBehaviour {
velocity.x = 0f; velocity.x = 0f;
} }
setJumpState(JumpState.Ascending); setJumpState(JumpState.Ascending);
break;
} else { } else {
velocity.y = gravity * Time.deltaTime; velocity.y = gravity * Time.deltaTime;
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed); velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
@ -88,7 +91,18 @@ public class PlayerController : MonoBehaviour {
// the drag coefficient gets bigger as we ascend, terminating at 1 // the drag coefficient gets bigger as we ascend, terminating at 1
float dragCoefficient = n * n; float dragCoefficient = n * n;
if (Input.GetButton("Jump")) { if (Input.GetButtonDown("Jump") && jumpCount < maxJumps) {
velocity.y = jumpVelocity;
if (input.x >= 0.25f) {
velocity.x = moveSpeed*maxForwardJumpBoost;
} else if (input.x <= -0.25f) {
velocity.x = -moveSpeed*maxForwardJumpBoost;
} else {
velocity.x = 0f;
}
setJumpState(JumpState.Ascending);
break;
} else if (Input.GetButton("Jump")) {
float jumpDrag = jumpVelocity * dragCoefficient; float jumpDrag = jumpVelocity * dragCoefficient;
if (n <= 0.7) { if (n <= 0.7) {
jumpDrag = 0; jumpDrag = 0;
@ -137,7 +151,7 @@ public class PlayerController : MonoBehaviour {
case JumpState.Apex: case JumpState.Apex:
tracer.color = Color.magenta; tracer.color = Color.magenta;
if (Input.GetButtonDown("Jump")) { if (Input.GetButtonDown("Jump") && jumpCount < maxJumps) {
velocity.y = jumpVelocity; velocity.y = jumpVelocity;
if (input.x >= 0.25f) { if (input.x >= 0.25f) {
velocity.x = moveSpeed*maxForwardJumpBoost; velocity.x = moveSpeed*maxForwardJumpBoost;
@ -147,6 +161,7 @@ public class PlayerController : MonoBehaviour {
velocity.x = 0f; velocity.x = 0f;
} }
setJumpState(JumpState.Ascending); setJumpState(JumpState.Ascending);
break;
} else { } else {
switch (jumpDirection) { switch (jumpDirection) {
case JumpDirection.Neutral: case JumpDirection.Neutral:
@ -174,6 +189,19 @@ public class PlayerController : MonoBehaviour {
case JumpState.Descending: case JumpState.Descending:
tracer.color = Color.yellow; tracer.color = Color.yellow;
if (Input.GetButtonDown("Jump") && jumpCount < maxJumps) {
velocity.y = jumpVelocity;
if (input.x >= 0.25f) {
velocity.x = moveSpeed*maxForwardJumpBoost;
} else if (input.x <= -0.25f) {
velocity.x = -moveSpeed*maxForwardJumpBoost;
} else {
velocity.x = 0f;
}
setJumpState(JumpState.Ascending);
break;
}
float n2 = (Time.time - jumpStateStart) / timeToJumpApex; float n2 = (Time.time - jumpStateStart) / timeToJumpApex;
n2 = Mathf.Clamp(n2, 0, 1); n2 = Mathf.Clamp(n2, 0, 1);
switch (jumpDirection) { switch (jumpDirection) {
@ -211,6 +239,19 @@ public class PlayerController : MonoBehaviour {
case JumpState.Falling: case JumpState.Falling:
tracer.color = Color.red; tracer.color = Color.red;
if (Input.GetButtonDown("Jump") && jumpCount < maxJumps) {
velocity.y = jumpVelocity;
if (input.x >= 0.25f) {
velocity.x = moveSpeed*maxForwardJumpBoost;
} else if (input.x <= -0.25f) {
velocity.x = -moveSpeed*maxForwardJumpBoost;
} else {
velocity.x = 0f;
}
setJumpState(JumpState.Ascending);
break;
}
switch (jumpDirection) { switch (jumpDirection) {
case JumpDirection.Neutral: case JumpDirection.Neutral:
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed); velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
@ -265,6 +306,13 @@ public class PlayerController : MonoBehaviour {
} else { } else {
jumpDirection = JumpDirection.Left; jumpDirection = JumpDirection.Left;
} }
if (state == JumpState.Grounded) {
jumpCount = 0;
}
if (state == JumpState.Ascending) {
jumpCount++;
}
} }
/* /*

Loading…
Cancel
Save