losing momentum when hitting a block should work

player also rotates to face the direction they are moving
This commit is contained in:
Melbyj1125
2022-03-20 06:53:42 -05:00
parent 3481c5087a
commit 4d806060a7
7 changed files with 334 additions and 93 deletions

View File

@@ -30,6 +30,7 @@ public class dMoveStateManager : NetworkBehaviour
////Objects Sections
private GameObject parentObj; // Parent object
private GameObject playerModel; // player visual model
public Camera cam; // Camera object
////
@@ -91,6 +92,7 @@ public class dMoveStateManager : NetworkBehaviour
parentObj = transform.parent.gameObject; // set parent object
animator = GetComponent<Animator>(); // set animator
animationManager = GetComponent<dAnimationManager>();
playerModel = GameObject.FindGameObjectWithTag("PlayerModel");
////
////Initialize Scripts
@@ -218,29 +220,33 @@ public class dMoveStateManager : NetworkBehaviour
vel = moveX + moveZ;
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
//Raycast offset
Vector3 rayOffset = moveXZ - lastVel;
/*
//Check if wall is in direction player is moving
if (((Physics.Raycast(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, moveXZ.normalized, out wallHitBot, .18f, layerMask) == true) || ((currentState != SlideState || currentState != CrouchState) && (Physics.Raycast(gameObject.transform.position + new Vector3(0,2.2f,0), moveXZ.normalized, out wallHitTop, .18f, layerMask) == true))) && !firstWallHit){
CancelMomentum();
Debug.Log("Collide");
firstWallHit = true;
}
if(((Physics.Raycast(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, moveXZ.normalized, out wallExitBot, .3f, layerMask) == false) && ((currentState == SlideState || currentState == CrouchState) || (Physics.Raycast(gameObject.transform.position + new Vector3(0,2.2f,0), moveXZ.normalized, out wallExitTop, .3f, layerMask) == false))) && firstWallHit){
firstWallHit = false;
}
Debug.DrawRay(gameObject.transform.position + new Vector3(0,.4f,0) + (rayOffset/2), moveXZ.normalized * 1f, Color.red);
Debug.DrawRay(gameObject.transform.position + new Vector3(0,2.2f,0) + rayOffset, moveXZ.normalized * .2f, Color.red);
*/
driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.CurTraction * Time.deltaTime);
if(currentState == GrappleAirState){
driftVel = Vector3.zero;
}
//Raycast offset
Vector3 rayOffset = driftVel - lastVel;
//Check if wall is in direction player is moving
if (((Physics.Raycast(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, driftVel.normalized, out wallHitBot, .18f, layerMask) == true) || ((currentState != SlideState || currentState != CrouchState) && (Physics.Raycast(gameObject.transform.position + new Vector3(0,2.2f,0), driftVel.normalized, out wallHitTop, .18f, layerMask) == true))) && !firstWallHit){
CancelMomentum();
Debug.Log("Collide");
firstWallHit = true;
}
if(((Physics.Raycast(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, driftVel.normalized, out wallExitBot, .3f, layerMask) == false) && ((currentState == SlideState || currentState == CrouchState) || (Physics.Raycast(gameObject.transform.position + new Vector3(0,2.2f,0), driftVel.normalized, out wallExitTop, .3f, layerMask) == false))) && firstWallHit){
firstWallHit = false;
}
Debug.DrawRay(gameObject.transform.position + new Vector3(0,.4f,0) + (rayOffset/2), moveXZ.normalized * .2f, Color.red);
Debug.DrawRay(gameObject.transform.position + new Vector3(0,2.2f,0) + rayOffset, moveXZ.normalized * .2f, Color.red);
if(driftVel != Vector3.zero){
playerModel.transform.rotation = Quaternion.LookRotation(driftVel.normalized);
}
//Actually move he player
moveController.Move(driftVel);
}
@@ -314,6 +320,11 @@ public class dMoveStateManager : NetworkBehaviour
driftVel = Vector3.zero;
}
//Verify Movement
private void VerifyMovement(){
}
//Apply Wind movement to the player
public void ApplyWind(bool wind){
if(wind){