mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-23 19:04:32 -05:00
Semi-Fixed Wallrunning
This commit is contained in:
@@ -9,16 +9,16 @@ public class dWallRun : NetworkBehaviour
|
||||
|
||||
public float wallMaxDistance = 5;
|
||||
public float wallSpeedMultiplier = 1.2f;
|
||||
public float minimumHeight = 1.2f;
|
||||
public float minimumHeight = .1f;
|
||||
public float maxAngleRoll = 20;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float normalizedAngleThreshold = 0.1f;
|
||||
|
||||
public float jumpDuration = 1;
|
||||
public float jumpDuration = .02f;
|
||||
public float wallBouncing = 3;
|
||||
public float cameraTransitionDuration = 1;
|
||||
|
||||
public float wallGravityDownForce = 20f;
|
||||
public float wallGravityDownForce = 5f;
|
||||
|
||||
[Space]
|
||||
dPlayerMovement playerMovementController;
|
||||
@@ -65,12 +65,13 @@ public class dWallRun : NetworkBehaviour
|
||||
|
||||
|
||||
public void WallRunRoutine()
|
||||
{
|
||||
|
||||
{
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
isWallRunning = false;
|
||||
|
||||
hits = new RaycastHit[directions.Length];
|
||||
|
||||
if(playerMovementController.GetJumpPressed())
|
||||
{
|
||||
jumping = true;
|
||||
@@ -78,24 +79,22 @@ public class dWallRun : NetworkBehaviour
|
||||
|
||||
if(CanAttach())
|
||||
{
|
||||
hits = new RaycastHit[directions.Length];
|
||||
|
||||
for(int i=0; i<directions.Length; i++)
|
||||
{
|
||||
Vector3 dir = transform.TransformDirection(directions[i]);
|
||||
Physics.Raycast(transform.position, dir, out hits[i], wallMaxDistance);
|
||||
//if(hits[i].collider != null)
|
||||
//{
|
||||
//Debug.DrawRay(transform.position, dir * hits[i].distance, Color.green);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
//Debug.DrawRay(transform.position, dir * wallMaxDistance, Color.red);
|
||||
//}
|
||||
if(hits[i].collider != null)
|
||||
{
|
||||
Debug.DrawRay(transform.position, dir * hits[i].distance, Color.green);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.DrawRay(transform.position, dir * wallMaxDistance, Color.red);
|
||||
}
|
||||
}
|
||||
|
||||
if(CanWallRun())
|
||||
{
|
||||
{
|
||||
hits = hits.ToList().Where(h => h.collider != null).OrderBy(h => h.distance).ToArray();
|
||||
if(hits.Length > 0)
|
||||
{
|
||||
@@ -119,6 +118,7 @@ public class dWallRun : NetworkBehaviour
|
||||
{
|
||||
elapsedTimeSinceWallAttach = 0;
|
||||
elapsedTimeSinceWallDetatch += Time.deltaTime;
|
||||
playerMovementController.AddPlayerVelocity((Vector3.down * playerMovementController.pStats.PlayerGrav * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,20 +141,23 @@ public class dWallRun : NetworkBehaviour
|
||||
float d = Vector3.Dot(hit.normal, Vector3.up);
|
||||
if(d >= -normalizedAngleThreshold && d <= normalizedAngleThreshold)
|
||||
{
|
||||
// Vector3 alongWall = Vector3.Cross(hit.normal, Vector3.up);
|
||||
Vector3 alongWall = Vector3.Cross(hit.normal, Vector3.up);
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
Vector3 alongWall = transform.TransformDirection(Vector3.forward);
|
||||
//Vector3 alongWall = transform.TransformDirection(Vector3.forward);
|
||||
|
||||
//Debug.DrawRay(transform.position, alongWall.normalized * 10, Color.green);
|
||||
//Debug.DrawRay(transform.position, lastWallNormal * 10, Color.magenta);
|
||||
// Debug.DrawRay(transform.position, alongWall.normalized * 10, Color.green);
|
||||
// Debug.DrawRay(transform.position, lastWallNormal * 10, Color.magenta);
|
||||
|
||||
Vector3 moveToSet = alongWall * vertical * playerMovementController.PlayerSpeed() *Time.deltaTime;// * wallSpeedMultiplier;
|
||||
Vector3 moveToSet = alongWall * vertical * playerMovementController.PlayerSpeed() * Time.deltaTime;// * wallSpeedMultiplier;
|
||||
Vector3 velNorm = playerMovementController.vel;
|
||||
velNorm.Normalize();
|
||||
moveToSet = new Vector3(moveToSet.x * -velNorm.x, moveToSet.y, moveToSet.z * -velNorm.z);
|
||||
moveToSet.y = 0;
|
||||
|
||||
|
||||
playerMovementController.SetPlayerVelocity(moveToSet);
|
||||
//Debug.Log("On Wall");
|
||||
Debug.Log(moveToSet);
|
||||
isWallRunning = true;
|
||||
Debug.Log("Is Wallrunning");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,18 +173,6 @@ public class dWallRun : NetworkBehaviour
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetCameraRoll() //Cause camera to roll when wall running - call to this is player movement
|
||||
{
|
||||
float dir = CalculateSide();
|
||||
float cameraAngle = playerMovementController.GetPlayerCamera().transform.eulerAngles.z;
|
||||
float targetAngle = 0;
|
||||
if(dir != 0)
|
||||
{
|
||||
targetAngle = Mathf.Sign(dir) * maxAngleRoll;
|
||||
}
|
||||
return Mathf.LerpAngle(cameraAngle, targetAngle, Mathf.Max(elapsedTimeSinceWallAttach, elapsedTimeSinceWallDetatch) / cameraTransitionDuration);
|
||||
}
|
||||
|
||||
public Vector3 GetWallJumpDirection() //Add call in jump where if we are wallrunning and jump, the jump vector is multiplied by this
|
||||
{
|
||||
if(isWallRunning)
|
||||
|
||||
@@ -344,7 +344,7 @@ public class dPlayerMovement : NetworkBehaviour
|
||||
tempSet = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else if(!jumpPressed && pStats.HasGlider){
|
||||
|
||||
if(tempSet == true){
|
||||
pStats.Traction = tempTraction;
|
||||
@@ -356,7 +356,7 @@ public class dPlayerMovement : NetworkBehaviour
|
||||
}
|
||||
|
||||
//Wallrunning
|
||||
if (pStats.HasWallrun) { wallRun.WallRunRoutine(); } //adjusted later if we are wallrunning
|
||||
else if (pStats.HasWallrun) { wallRun.WallRunRoutine(); } //adjusted later if we are wallrunning
|
||||
//If gliding
|
||||
//Go down slowly
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@ using UnityEngine.Rendering;
|
||||
public class WallRun : NetworkBehaviour
|
||||
{
|
||||
|
||||
public float wallMaxDistance = 1;
|
||||
public float wallMaxDistance = 5;
|
||||
public float wallSpeedMultiplier = 1.2f;
|
||||
public float minimumHeight = 1.2f;
|
||||
public float minimumHeight = .1f;
|
||||
public float maxAngleRoll = 20;
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float normalizedAngleThreshold = 0.1f;
|
||||
|
||||
public float jumpDuration = 1;
|
||||
public float jumpDuration = .02f;
|
||||
public float wallBouncing = 3;
|
||||
public float cameraTransitionDuration = 1;
|
||||
|
||||
public float wallGravityDownForce = 20f;
|
||||
public float wallGravityDownForce = 5f;
|
||||
|
||||
[Space]
|
||||
PlayerMovement playerMovementController;
|
||||
@@ -33,7 +33,6 @@ public class WallRun : NetworkBehaviour
|
||||
float elapsedTimeSinceWallAttach = 0;
|
||||
float elapsedTimeSinceWallDetatch = 0;
|
||||
bool jumping;
|
||||
private bool regainedJump = false;
|
||||
|
||||
bool isPlayergrounded() => playerMovementController.isGrounded;
|
||||
|
||||
@@ -42,7 +41,6 @@ public class WallRun : NetworkBehaviour
|
||||
bool CanWallRun()
|
||||
{
|
||||
float verticalAxis = Input.GetAxisRaw("Vertical");
|
||||
|
||||
return !isPlayergrounded() && verticalAxis > 0 && VerticalCheck();
|
||||
}
|
||||
|
||||
@@ -67,11 +65,13 @@ public class WallRun : NetworkBehaviour
|
||||
|
||||
|
||||
public void WallRunRoutine()
|
||||
{
|
||||
if (!IsLocalPlayer) { return; }
|
||||
{
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
isWallRunning = false;
|
||||
|
||||
hits = new RaycastHit[directions.Length];
|
||||
|
||||
if(playerMovementController.GetJumpPressed())
|
||||
{
|
||||
jumping = true;
|
||||
@@ -79,24 +79,22 @@ public class WallRun : NetworkBehaviour
|
||||
|
||||
if(CanAttach())
|
||||
{
|
||||
hits = new RaycastHit[directions.Length];
|
||||
|
||||
for(int i=0; i<directions.Length; i++)
|
||||
{
|
||||
Vector3 dir = transform.TransformDirection(directions[i]);
|
||||
Physics.Raycast(transform.position, dir, out hits[i], wallMaxDistance);
|
||||
//if(hits[i].collider != null)
|
||||
//{
|
||||
//Debug.DrawRay(transform.position, dir * hits[i].distance, Color.green);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
//Debug.DrawRay(transform.position, dir * wallMaxDistance, Color.red);
|
||||
//}
|
||||
// if(hits[i].collider != null)
|
||||
// {
|
||||
// Debug.DrawRay(transform.position, dir * hits[i].distance, Color.green);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.DrawRay(transform.position, dir * wallMaxDistance, Color.red);
|
||||
// }
|
||||
}
|
||||
|
||||
if(CanWallRun())
|
||||
{
|
||||
{
|
||||
hits = hits.ToList().Where(h => h.collider != null).OrderBy(h => h.distance).ToArray();
|
||||
if(hits.Length > 0)
|
||||
{
|
||||
@@ -115,17 +113,12 @@ public class WallRun : NetworkBehaviour
|
||||
elapsedTimeSinceWallDetatch = 0;
|
||||
elapsedTimeSinceWallAttach += Time.deltaTime;
|
||||
playerMovementController.AddPlayerVelocity((Vector3.down * wallGravityDownForce * Time.deltaTime));
|
||||
if (elapsedTimeSinceWallAttach > 0.125f && regainedJump == false)//Allows players to always jump off of walls
|
||||
{
|
||||
regainedJump = true;
|
||||
playerMovementController.decrementCurrentJumpNumber();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsedTimeSinceWallAttach = 0;
|
||||
elapsedTimeSinceWallDetatch += Time.deltaTime;
|
||||
regainedJump = false;
|
||||
playerMovementController.AddPlayerVelocity((Vector3.down * playerMovementController.pStats.PlayerGrav * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,19 +141,22 @@ public class WallRun : NetworkBehaviour
|
||||
float d = Vector3.Dot(hit.normal, Vector3.up);
|
||||
if(d >= -normalizedAngleThreshold && d <= normalizedAngleThreshold)
|
||||
{
|
||||
// Vector3 alongWall = Vector3.Cross(hit.normal, Vector3.up);
|
||||
Vector3 alongWall = Vector3.Cross(hit.normal, Vector3.up);
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
Vector3 alongWall = transform.TransformDirection(Vector3.forward);
|
||||
//Vector3 alongWall = transform.TransformDirection(Vector3.forward);
|
||||
|
||||
//Debug.DrawRay(transform.position, alongWall.normalized * 10, Color.green);
|
||||
//Debug.DrawRay(transform.position, lastWallNormal * 10, Color.magenta);
|
||||
// Debug.DrawRay(transform.position, alongWall.normalized * 10, Color.green);
|
||||
// Debug.DrawRay(transform.position, lastWallNormal * 10, Color.magenta);
|
||||
|
||||
Vector3 moveToSet = alongWall * vertical * playerMovementController.PlayerSpeed() *Time.deltaTime;// * wallSpeedMultiplier;
|
||||
Vector3 moveToSet = alongWall * vertical * playerMovementController.PlayerSpeed() * Time.deltaTime;// * wallSpeedMultiplier;
|
||||
Vector3 velNorm = playerMovementController.vel;
|
||||
velNorm.Normalize();
|
||||
moveToSet = new Vector3(moveToSet.x * -velNorm.x, moveToSet.y, moveToSet.z * -velNorm.z);
|
||||
moveToSet.y = 0;
|
||||
Vector3 cancelDrop = new Vector3(0, 0.01f, 0);
|
||||
|
||||
|
||||
playerMovementController.SetPlayerVelocity(moveToSet);
|
||||
playerMovementController.AddPlayerVelocity(cancelDrop);
|
||||
//Debug.Log("On Wall");
|
||||
Debug.Log(moveToSet);
|
||||
isWallRunning = true;
|
||||
}
|
||||
}
|
||||
@@ -177,18 +173,6 @@ public class WallRun : NetworkBehaviour
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float GetCameraRoll() //Cause camera to roll when wall running - call to this is player movement
|
||||
{
|
||||
float dir = CalculateSide();
|
||||
float cameraAngle = playerMovementController.GetPlayerCamera().transform.eulerAngles.z;
|
||||
float targetAngle = 0;
|
||||
if(dir != 0)
|
||||
{
|
||||
targetAngle = Mathf.Sign(dir) * maxAngleRoll;
|
||||
}
|
||||
return Mathf.LerpAngle(cameraAngle, targetAngle, Mathf.Max(elapsedTimeSinceWallAttach, elapsedTimeSinceWallDetatch) / cameraTransitionDuration);
|
||||
}
|
||||
|
||||
public Vector3 GetWallJumpDirection() //Add call in jump where if we are wallrunning and jump, the jump vector is multiplied by this
|
||||
{
|
||||
if(isWallRunning)
|
||||
|
||||
Reference in New Issue
Block a user