Commit 862e7590 authored by kgingras's avatar kgingras
Browse files

CC modified

parent c9bb8362
......@@ -48,16 +48,22 @@ public class CapsuleController : MonoBehaviour {
Ray ray;
RaycastHit hit;
if (Input.GetKeyUp(KeyCode.B)){ // jump pressed:
// if (Physics.Raycast(transform.position, -myNormal, out hit, jumpRange)){ // wall ahead?
// // JumpToWall(hit.point, hit.normal); // yes: jump to the wall
// }
if (isGrounded){ // no: if grounded, jump up
Debug.Log("jump");
rb.AddForce(jumpSpeed * myNormal);
}
}
// if (Input.GetKeyUp(KeyCode.B)){ // jump pressed:
//
//// if (Physics.Raycast(transform.position, -myNormal, out hit, jumpRange)){ // wall ahead?
//// // JumpToWall(hit.point, hit.normal); // yes: jump to the wall
//// }
// if (isGrounded){ // no: if grounded, jump up
// Debug.Log("jump");
// isGrounded = false;
////
//// Vector3 velocity = rb.velocity;
////
//// velocity += jumpSpeed * myNormal;
// rb.AddForce(jumpSpeed * myNormal, ForceMode.Impulse);
//
// }
// }
if (Physics.Raycast(transform.position, -myNormal, out hit, Mathf.Infinity)){ // use it to update myNormal and isGrounded
isGrounded = hit.distance <= distGround + deltaGround;
......@@ -69,22 +75,46 @@ public class CapsuleController : MonoBehaviour {
// assume usual ground normal to avoid "falling forever"
surfaceNormal = Vector3.up;
}
myNormal = Vector3.Lerp(myNormal, surfaceNormal, lerpSpeed*Time.deltaTime);
if (isGrounded) {
myNormal = Vector3.Lerp (myNormal, surfaceNormal, lerpSpeed * Time.deltaTime);
} else {
myNormal = Vector3.Lerp (myNormal, Vector3.up, lerpSpeed * Time.deltaTime);
}
Debug.Log (myNormal + " normal normal" + myNormal.normalized);
GetMouseLook();
GetMovement();
if (isGrounded) {
AddGravity ();
} else {
AddRealGravity();
}
// if (isGrounded) {
// AddGravity ();
// } else {
// AddRealGravity();
// }
}
void GetMovement(){
if (Input.GetKeyUp(KeyCode.B)){ // jump pressed:
// if (Physics.Raycast(transform.position, -myNormal, out hit, jumpRange)){ // wall ahead?
// // JumpToWall(hit.point, hit.normal); // yes: jump to the wall
// }
if (isGrounded){ // no: if grounded, jump up
Debug.Log("jump");
isGrounded = false;
//
// Vector3 velocity = rb.velocity;
//
// velocity += jumpSpeed * myNormal;
rb.AddForce(jumpSpeed * myNormal, ForceMode.Impulse);
}
return;
}
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
......@@ -98,8 +128,22 @@ public class CapsuleController : MonoBehaviour {
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, lerpSpeed*Time.deltaTime);
Vector3 targetVelocity = myForward * v + myRight * h;
///add gravity here
// if (isGrounded) {
// targetVelocity += -gravityForce*myNormal;
// }
targetVelocity *= walkSpeed;
if(!isGrounded) {
targetVelocity += -gravityForce*Vector3.up;
}
Vector3 velocity = rb.velocity;
Vector3 velocityChange = (targetVelocity - velocity);
rb.AddForce(velocityChange, ForceMode.VelocityChange);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment