Compare commits

..
Author SHA1 Message Date
Gregory Campbell e6db8a979c Cleaned up the expanded area and gave all obstacles more space between each other as well as fine tuning and fixing all noticeable issuses with all crouch based movements 2020-01-05 12:56:23 -05:00
Gregory Campbell d4fafd63d3 Implemented a long jump, a dive, the ability to bunny hop and a somewhat messy fix to the straight down drop issue from the implemented gravity as well as expanding the test area to more easily test quick movements 2020-01-05 01:45:45 -05:00
Gregory CampbellandGitHub 081d93f2c2 Merge pull request #18 from gjcampbell777/acceleration_rework
Acceleration rework
2020-01-04 16:15:56 -05:00
Gregory Campbell 996e1e3b20 Fully functional and satisfactory acc/decc in movement (although a little slippery, might require more tweakign later on) 2020-01-04 16:15:15 -05:00
Gregory Campbell 386b51589e Got a fully functional implementation of acceleration/decceleration that meshes well across all inputs. Will do further testing/tinkering before merging 2020-01-04 15:52:45 -05:00
Gregory Campbell 573b4815ea Havent made any real progress, stopping and saving this now to work on other things 2020-01-04 15:02:05 -05:00
Gregory CampbellandGitHub db8ae256a8 Merge pull request #17 from gjcampbell777/wall_running
Wall running
2019-12-31 18:18:34 -05:00
Gregory Campbell 9818b32bdc Got a functional implementation of wall running that I am satisfied with 2019-12-31 18:17:35 -05:00
Gregory Campbell f1db804155 Implemented basic wallrunning 2019-12-21 23:17:24 -05:00
Gregory CampbellandGitHub a31a335424 Merge pull request #16 from gjcampbell777/add_momentum_to_movement
Add momentum to movement
2019-12-21 21:03:56 -05:00
Gregory Campbell e638892592 Got momentum based movement fully functional while fixing a few player controller bugs and preferential tweaks 2019-12-21 21:00:36 -05:00
Gregory Campbell 3afdbc4ff0 Fixed issue causing no increased or decreased mmovement based on changing moveset 2019-12-14 23:49:23 -05:00
Gregory Campbell a292dd8b9a Added momentum to player movement and made adjustments to public player variables 2019-12-14 23:40:14 -05:00
Gregory Campbell 31fc08bd5b Slight tweak to improve upon the last merge 2019-12-11 21:33:57 -05:00
Gregory CampbellandGitHub b83c37531a Merge pull request #15 from gjcampbell777/fix_delayed_standing_slide_bug
Fixed delayed standing slide and made standard horz/vert axis movemen…
2019-12-11 21:14:01 -05:00
4 changed files with 209 additions and 52 deletions
+26 -24
View File
@@ -167,7 +167,7 @@ GameObject:
- component: {fileID: 194035205}
m_Layer: 0
m_Name: Running Wall Left
m_TagString: Environment
m_TagString: Wall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@@ -180,8 +180,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 194035203}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 62, y: 6.5, z: 12}
m_LocalScale: {x: 25, y: 20, z: 0.25}
m_LocalPosition: {x: 155, y: 6.5, z: 12}
m_LocalScale: {x: 75, y: 20, z: 0.25}
m_Children: []
m_Father: {fileID: 1013482115}
m_RootOrder: 0
@@ -273,7 +273,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 195913138}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 21, y: 2.5, z: -30}
m_LocalPosition: {x: 42, y: 2.5, z: -49.5}
m_LocalScale: {x: 10, y: 5, z: 10}
m_Children: []
m_Father: {fileID: 746704017}
@@ -366,8 +366,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 203887784}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 84, y: -0.5, z: 6}
m_LocalScale: {x: 20, y: 0.5, z: 12}
m_LocalPosition: {x: 200, y: -0.5, z: 6}
m_LocalScale: {x: 50, y: 0.5, z: 50}
m_Children: []
m_Father: {fileID: 833538478}
m_RootOrder: 2
@@ -459,7 +459,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 241158957}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -25, y: 2, z: 22}
m_LocalPosition: {x: -50, y: 2, z: 45}
m_LocalScale: {x: 1, y: 1, z: 5}
m_Children: []
m_Father: {fileID: 1488444358}
@@ -552,7 +552,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 432077771}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -35, y: 5, z: -20}
m_LocalPosition: {x: -63, y: 5, z: -37}
m_LocalScale: {x: 10, y: 1, z: 10}
m_Children: []
m_Father: {fileID: 942294095}
@@ -645,7 +645,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 478907417}
m_LocalRotation: {x: 0, y: 0, z: 0.38268343, w: 0.92387956}
m_LocalPosition: {x: 15, y: 7, z: 40}
m_LocalPosition: {x: 45, y: 7, z: 60}
m_LocalScale: {x: 25, y: 5, z: 7}
m_Children: []
m_Father: {fileID: 1833724898}
@@ -832,7 +832,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 654784537}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -25, y: 2, z: -10}
m_LocalPosition: {x: -53, y: 2, z: -27}
m_LocalScale: {x: 10, y: 1, z: 10}
m_Children: []
m_Father: {fileID: 942294095}
@@ -1017,7 +1017,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 717001268}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -25.5, y: 2, z: 36}
m_LocalPosition: {x: -49, y: 2, z: 58}
m_LocalScale: {x: 14, y: 1, z: 7}
m_Children: []
m_Father: {fileID: 1488444358}
@@ -1111,7 +1111,7 @@ Transform:
m_GameObject: {fileID: 736244541}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 100, y: 0.5, z: 100}
m_LocalScale: {x: 250, y: 0.5, z: 250}
m_Children: []
m_Father: {fileID: 833538478}
m_RootOrder: 0
@@ -1205,7 +1205,7 @@ CapsuleCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 741217452}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_IsTrigger: 1
m_Enabled: 1
m_Radius: 0.5
m_Height: 2
@@ -1284,7 +1284,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 83127dd120c01de45954b99cc4d669a5, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 20
maxSpeed: 25
acceleration: 0.5
friction: 0.1
jumpHeight: 20
gravity: 5
rotationSpeed: 20
@@ -1388,7 +1390,7 @@ GameObject:
- component: {fileID: 858957127}
m_Layer: 0
m_Name: Running Wall Right
m_TagString: Environment
m_TagString: Wall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@@ -1401,8 +1403,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 858957125}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 62, y: 6.5, z: 0}
m_LocalScale: {x: 25, y: 20, z: 0.25}
m_LocalPosition: {x: 155, y: 6.5, z: 0}
m_LocalScale: {x: 75, y: 20, z: 0.25}
m_Children: []
m_Father: {fileID: 1013482115}
m_RootOrder: 1
@@ -1664,7 +1666,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1194166061}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -36, y: 2, z: 25.5}
m_LocalPosition: {x: -59.5, y: 2, z: 47.5}
m_LocalScale: {x: 7, y: 1, z: 14}
m_Children: []
m_Father: {fileID: 1488444358}
@@ -1821,7 +1823,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1509260413}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 28, y: 5, z: -23}
m_LocalPosition: {x: 49, y: 5, z: -42.5}
m_LocalScale: {x: 10, y: 10, z: 10}
m_Children: []
m_Father: {fileID: 746704017}
@@ -1914,7 +1916,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1810553729}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -22, y: 2, z: 25}
m_LocalPosition: {x: -47, y: 2, z: 48}
m_LocalScale: {x: 5, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1488444358}
@@ -2042,8 +2044,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1853948297}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 62, y: -3.5, z: 6}
m_LocalScale: {x: 25, y: 0.25, z: 12}
m_LocalPosition: {x: 155, y: -3.5, z: 6}
m_LocalScale: {x: 75, y: 0.25, z: 12}
m_Children: []
m_Father: {fileID: 833538478}
m_RootOrder: 1
@@ -2135,7 +2137,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1943602250}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 19, y: 1, z: -21}
m_LocalPosition: {x: 40, y: 1, z: -40.5}
m_LocalScale: {x: 10, y: 2, z: 10}
m_Children: []
m_Father: {fileID: 746704017}
@@ -2228,7 +2230,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2057687440}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -20, y: 10, z: -30}
m_LocalPosition: {x: -48, y: 10, z: -47}
m_LocalScale: {x: 10, y: 1, z: 10}
m_Children: []
m_Father: {fileID: 942294095}
+180 -26
View File
@@ -12,21 +12,38 @@ public class PlayerController : MonoBehaviour
CharacterController characterController;
CapsuleCollider capsule;
public float speed;
public float maxSpeed;
public float acceleration;
public float friction;
public float jumpHeight;
public float gravity;
public float rotationSpeed;
public Transform pivot;
public GameObject playerModel;
private bool wallRunning = false;
private bool diving = false;
private bool sliding = false;
private int jump = 0;
private int wall = 0;
private int dive = 0;
private float maxSpeedStore;
private float maxSpeedCap = 100;
private float accelerationStore;
private float capsuleHeight;
private float controllerHeight;
private float transformHeight;
private float xVelocity = 0.0f;
private float zVelocity = 0.0f;
private Vector3 moveDirection;
private Vector3 velocity;
private Vector3 gravityVelocity;
float startTime = 0.0f;
float slideTime = 0.0f;
float wallRunTime = 0.0f;
float oneSec = 1.0f;
float halfSec = 0.5f;
float quarterSec = 0.25f;
void Start()
{
@@ -35,34 +52,61 @@ public class PlayerController : MonoBehaviour
transformHeight = transform.localScale.y;
controllerHeight = characterController.height;
capsuleHeight = capsule.height;
maxSpeedStore = maxSpeed;
accelerationStore = acceleration;
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
if(hit.gameObject.tag == "Wall")
{
wallRunning = true;
wall++;
}
}
void Update()
{
float yStore = moveDirection.y;
//Need to switch to 'raw' when using keyboard
moveDirection = (transform.forward * Input.GetAxisRaw("Vertical")) + (transform.right * Input.GetAxisRaw("Horizontal"));
if (jump <= 1)
{
moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run
} else {
moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run
}
moveDirection = new Vector3(Input.GetAxis("Horizontal"), moveDirection.y, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
moveDirection.y = yStore;
if (jump >= 2)
{
if(maxSpeed > maxSpeedStore/1.5f)
{
maxSpeed -= acceleration;
}
}
if (characterController.isGrounded)
{
diving = false;
dive = 0;
jump = 0;
moveDirection.y = 0.0f;
if(maxSpeed > maxSpeedStore)
{
maxSpeed -= acceleration/10;
}
if(maxSpeed < maxSpeedStore && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.LeftControl))
{
maxSpeed += acceleration;
}
if(Input.GetKey(KeyCode.LeftShift))
{
moveDirection = (moveDirection.normalized * speed/2);
} else {
moveDirection = moveDirection.normalized * speed;
if(maxSpeed > maxSpeedStore/2)
{
maxSpeed -= acceleration;
}
}
if(Input.GetKey(KeyCode.LeftControl))
@@ -72,30 +116,77 @@ public class PlayerController : MonoBehaviour
capsule.height /= 2;
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
if(Input.GetKeyDown(KeyCode.LeftControl) && characterController.velocity != new Vector3(0, 0, 0))
if(Input.GetKeyDown(KeyCode.LeftControl))
{
startTime = Time.time;
}
if((Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0))
{
sliding = false;
} else {
sliding = true;
slideTime = Time.time;
}
}
if(startTime + oneSec >= Time.time)
if(slideTime + halfSec >= Time.time && sliding == true)
{
moveDirection = (moveDirection.normalized * speed * 2);
if(maxSpeed < maxSpeedStore*2)
{
maxSpeed += acceleration*2;
}
if(Input.GetButton("Jump") && slideTime + quarterSec >= Time.time)
{
maxSpeed += 5;
}
} else {
moveDirection = (moveDirection.normalized * speed/4);
if(maxSpeed > maxSpeedStore/4)
{
maxSpeed -= acceleration;
}
}
} else {
moveDirection = moveDirection.normalized * speed;
characterController.height = controllerHeight;
capsule.height = capsuleHeight;
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
}
}
} else {
slideTime = Time.time;
if(Input.GetKey(KeyCode.LeftControl))
{
characterController.height /= 2;
capsule.height /= 2;
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
diving = true;
} else {
characterController.height = controllerHeight;
capsule.height = capsuleHeight;
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
}
//Might want to change move direction value to make triggering this speed up effect easier/harder
if(diving && moveDirection.y > 0.75 && Input.GetKeyDown(KeyCode.LeftControl))
{
dive++;
if(dive == 1){
maxSpeed += 10;
}
}
}
if (Input.GetButtonDown("Jump") && jump <= 1)
{
@@ -103,13 +194,76 @@ public class PlayerController : MonoBehaviour
jump++;
}
if (characterController.collisionFlags == CollisionFlags.None)
{
wallRunning = false;
wall = 0;
}
moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime;
if (wallRunning)
{
if(maxSpeed < maxSpeedStore*1.5f)
{
maxSpeed += acceleration;
}
jump = 0;
if(wall == 1)
{
wallRunTime = Time.time;
}
if(wallRunTime + oneSec < Time.time)
{
moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime;
} else {
moveDirection.y = 0.0f;
}
}
velocity.x += moveDirection.x;
velocity.z += moveDirection.z;
if(Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0){
//Remove or "lower" friction to add an 'ice' effect
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction);
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction);
}
if(maxSpeed > maxSpeedCap)
{
maxSpeed = maxSpeedCap;
}
if(characterController.velocity == new Vector3(0, 0, 0))
{
maxSpeed = maxSpeedStore;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
velocity.y = moveDirection.y;
Debug.Log(moveDirection.y+"\n");
if(moveDirection.y <= -5 && Mathf.Abs(velocity.x) <= 1.5f && Mathf.Abs(velocity.z) <= 1.5f)
{
velocity.x = velocity.x * Mathf.Abs(moveDirection.y);
velocity.z = velocity.z * Mathf.Abs(moveDirection.y);
}
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
characterController.Move(velocity * Time.deltaTime);
//Move the player in different directions based on camera look direction
//Need to switch to 'raw' when using keyboard
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
{
transform.rotation = Quaternion.Euler(0f, pivot.rotation.eulerAngles.y, 0f);
+2 -2
View File
@@ -16,7 +16,7 @@ InputManager:
gravity: 1000
dead: 0.001
sensitivity: 3
snap: 1
snap: 0
invert: 0
type: 0
axis: 0
@@ -32,7 +32,7 @@ InputManager:
gravity: 1000
dead: 0.001
sensitivity: 3
snap: 1
snap: 0
invert: 0
type: 0
axis: 0
+1
View File
@@ -5,6 +5,7 @@ TagManager:
serializedVersion: 2
tags:
- Environment
- Wall
layers:
- Default
- TransparentFX