This commit is contained in:
Katherine
2021-10-11 13:45:31 -05:00
68 changed files with 8103 additions and 90 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7c3b0fb28afc8e04c8324830d2bbcc2f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InventoryManager : MonoBehaviour
{
public Item[] allItems;
private List<Item> itemList;
public List<Item> ItemList{
get{ return itemList; }
set{ itemList = value; }
}
void Awake(){
allItems = Resources.LoadAll<Item>("ItemObjects");
itemList = new List<Item>(allItems);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 66519fc5420181e45850c591aa1179ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class Item: ScriptableObject {
public int id;
public string itemName;
public string description;
[Space]
public float maxVelM;
public float minVelM;
public float curVelM;
public float accM;
public float jumpPowM;
public int jumpNumM;
public float tractionM;
public float kickPowM;
public float recovTimeM;
public float playerGravM;
public void Equip(PlayerStats p){
if(maxVelM != 0){
p.MaxVel += maxVelM;
}
if(minVelM != 0){
p.MinVel += minVelM;
}
if(curVelM != 0){
p.CurVel += curVelM;
}
if(accM != 0){
p.Acc += accM;
}
if(jumpPowM != 0){
p.JumpPow += jumpPowM;
}
if(jumpNumM != 0){
p.JumpNum += jumpNumM;
}
if(tractionM != 0){
p.Traction += tractionM;
}
if(kickPowM != 0){
p.KickPow += kickPowM;
}
if(playerGravM != 0){
p.PlayerGrav += playerGravM;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d76cac0a7f5ea2a4cadbec8ef3315ec1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3f81b99cf16b831458726bf10a114803
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e292b284ab595e24684a1ed7e69c6a2d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: QuickStandup
m_EditorClassIdentifier:
id: 4
itemName: QuickStandup
description: Player gets up faster
maxVelM: 0
minVelM: 0
curVelM: 0
accM: 0
jumpPowM: 0
jumpNumM: 0
tractionM: 0
kickPowM: 0
recovTimeM: 20
playerGravM: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a4f559eb10aa9b243a2a08c544802857
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: RollerSkates
m_EditorClassIdentifier:
id: 1
itemName: RollerSkates
description: More Slidey But Faster
maxVelM: 15
minVelM: 0
curVelM: 0
accM: 0.3
jumpPowM: 0
jumpNumM: 0
tractionM: -2.2
kickPowM: 0
recovTimeM: 0
playerGravM: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c6fce7543828d16448383a9e0c1d651d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: Springs
m_EditorClassIdentifier:
id: 2
itemName: Springs
description: Jump Higher
maxVelM: 0
minVelM: 0
curVelM: 0
accM: 0
jumpPowM: 100
jumpNumM: 0
tractionM: 0
kickPowM: 0
recovTimeM: 0
playerGravM: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ca4d5584eacf416478beba5cd283bfa3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: StrongerKick
m_EditorClassIdentifier:
id: 0
itemName:
description:
maxVelM: 0
minVelM: 0
curVelM: 0
accM: 0
jumpPowM: 0
jumpNumM: 0
tractionM: 0
kickPowM: 30
recovTimeM: 0
playerGravM: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a96dfb1a70e0d0a4f84c15378f38ce99
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d76cac0a7f5ea2a4cadbec8ef3315ec1, type: 3}
m_Name: TripleJump
m_EditorClassIdentifier:
id: 3
itemName: TripleJump
description: Player gets an extra jump but has less jump height
maxVelM: 0
minVelM: 0
curVelM: 0
accM: 0
jumpPowM: -50
jumpNumM: 1
tractionM: 0
kickPowM: 0
recovTimeM: 0
playerGravM: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6a839da810e4bd746bb2a72d791cb8a4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpecialItem : Item
{
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 220c578e08133f54a95a442eb87b3702
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallRunItem : Item
{
public void Equip(PlayerStats p){
p.HasWallrun = true;
}
public void Unequip(PlayerStats p)
{
p.HasWallrun = false;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 80dbcf4212f11a74ebd5289c2b5eb309
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,15 +4,4 @@ using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -4,15 +4,46 @@ using UnityEngine;
public class PlayerInventory : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//List of items
[SerializeField] List<Item> items;
//Scripts
public PlayerStats pStats;
public InventoryManager invMan;
public bool AddItem(Item item){
items.Add(item);
return true;
}
// Update is called once per frame
void Update()
{
public bool AddSpecialItem<T>(T itemCandidate) { // Unless we don't want the four special items to be handled by inventory/inventory manager?
if (itemCandidate is Item) {
items.Add(itemCandidate as Item);
}
return true;
}
public bool RemoveItem(Item item){
if(items.Remove(item)){
return true;
}
return false;
}
void Awake(){
pStats = GetComponent<PlayerStats>();
invMan = GetComponent<InventoryManager>();//////UPDATE WHEN THIS IS NO LONGER ATTACHED TO THE PLAYER
}
void Start(){
AddItem(invMan.ItemList[0]);
AddItem(invMan.ItemList[1]);
foreach (Item item in items){
Debug.Log(item.name);
item.Equip(pStats);
}
}
}

View File

@@ -5,7 +5,7 @@ using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
{
//Scripts
public PlayerStats pStats;
@@ -14,6 +14,10 @@ public class PlayerMovement : MonoBehaviour
//Speed Variables
public Vector3 vel;
private Vector3 moveZ;
private Vector3 moveX;
private Vector3 driftVel;
//Character Moving
private CharacterController moveController;
@@ -21,13 +25,28 @@ public class PlayerMovement : MonoBehaviour
private int curJumpNum;
private bool jumpPressed;
//Bump physics
float mass = 5.0F; // defines the character mass
Vector3 impact = Vector3.zero;
//Jump physics
private float mass = 5.0F; // defines the character mass
private Vector3 impact = Vector3.zero;
private float distToGround;
//Wallrunning
private WallRun wallRun;
//Ground Check
public bool isGrounded { get; private set; } //Better custom is grounded
public float groundCheckDistance = 0.05f; //how far away from the ground to not be considered grounded
private float lastTimeJumped = 0f; //Last time the player jumped
const float jumpGroundingPreventionTime = 0.2f; // delay in checking if we are grounded after a jump
const float groundCheckDistanceInAir = 0.07f; //How close we have to get to ground to start checking for grounded again
public LayerMask groundCheckLayers = -1; //Physics layers checked to consider the player grounded
//Camera Variables
private LayerMask ignoreP;
private Vector3 camRotation;
private Transform cam;
private Camera cam;
[Range(-45, -15)]
public int minAngle = -30;
@@ -35,6 +54,13 @@ public class PlayerMovement : MonoBehaviour
public int maxAngle = 45;
[Range(50, 500)]
public int sensitivity = 200;
//Blink Variables
private LineRenderer beam;
private Vector3 origin;
private Vector3 endPoint;
private Vector3 mousePos;
private RaycastHit hit;
/////
void Awake(){
@@ -42,23 +68,35 @@ public class PlayerMovement : MonoBehaviour
moveController = GetComponent<CharacterController>();
pStats = GetComponent<PlayerStats>();
Cursor.lockState = CursorLockMode.Locked;
ignoreP = LayerMask.GetMask("Player");
beam = gameObject.AddComponent<LineRenderer>();
beam.startWidth = 0.2f;
beam.endWidth = 0.2f;
//camera transform
cam = Camera.main.transform;
cam = Camera.main;
//Wallrun
wallRun = gameObject.GetComponent<WallRun>();
}
void Start(){
InitializeStats();
distToGround = GetComponent<Collider>().bounds.extents.y;
}
// Update is called once per frame
void FixedUpdate()
{
void FixedUpdate(){
//input controls for movement
InputController();
//Controls for camera
Rotate();
//if suffiecient impact magnitude is applied then move player
if (impact.magnitude > 0.2F) moveController.Move(impact * Time.deltaTime);
@@ -67,47 +105,40 @@ public class PlayerMovement : MonoBehaviour
//Checks if player should respawn
Respawn();
Blink();
}
//REMOVE OR ADJUST ONCE INVENTORY IS IMPLEMENTED
//Initializes variables for player when inventory is implemented it would be set there
private void InitializeStats(){
pStats.MaxVel = 30.0f;
pStats.MinVel = 2.0f;
pStats.CurVel = 0.0f;
pStats.Acc = 0.06f;
pStats.JumpPow = 100.0f;
pStats.JumpNum = 50;///SET IT LIKE THIS BC OF THE ISSUE WITH ISGROUNDED
pStats.Traction = 3.0f;
pStats.PlayerGrav= 7.0f;
}
//Reads inputs and moves player
private void InputController(){
//Check if player is grounded before each frame
GroundCheck();
//Keyboard inputs
//Checks if movement keys have been pressed and calculates correct vector
Vector3 moveX = transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * PlayerSpeed();
Vector3 moveZ = transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * PlayerSpeed();
moveX = transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * PlayerSpeed();
moveZ = transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * PlayerSpeed();
//Adds vectors based on movement keys and other conditions to check what the
//player vector should be under the circumstances
vel = moveX + moveZ;
if(moveController.isGrounded) curJumpNum = 0;
//Gravity
Gravity();
driftVel = Vector3.Lerp(driftVel, vel, pStats.Traction*Time.deltaTime);
//Jump Function
Jump();
//Gravity
vel.y -= pStats.PlayerGrav * Time.deltaTime;
moveController.Move(driftVel);
}
moveController.Move(vel);
}
//Calculates speed current player needs to be going
private float PlayerSpeed(){
public float PlayerSpeed(){
//If nothing is pressed speed is 0
if(Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f){
pStats.CurVel = 0.0f;
@@ -130,6 +161,8 @@ public class PlayerMovement : MonoBehaviour
}
}
//Applies impact in a direction with the given force
public void AddImpact(Vector3 dir, float force){
dir.Normalize();
@@ -137,24 +170,47 @@ public class PlayerMovement : MonoBehaviour
impact += dir.normalized * force / mass;
}
//Jump Function
private void Jump(){
//If space is pressed apply an upwards force to the player
if(Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum < pStats.JumpNum){
if(Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum+1 < pStats.JumpNum){
AddImpact(transform.up, pStats.JumpPow);
curJumpNum++;
jumpPressed = true;
}
lastTimeJumped = Time.time;
//NEEDS TO BE MASSIVELY CHANGE LIKELY USE RAYCAST TO CHECK IF ACTUALLY ON GROUND
//CANNOT USE CHARACTERCONTROLLER.ISGROUNDED IT IS UNRELIABLE
//If grounded no jumps have been used
if(moveController.isGrounded) curJumpNum = 0;
// if(IsGrounded()){
// curJumpNum = 0;
// }
//If space isn't being pressed then jump is false
if(Input.GetAxis("Jump")==0) jumpPressed = false;
}
public bool GetJumpPressed() {
return jumpPressed;
}
public Camera GetPlayerCamera() {
return cam;
}
public void AddPlayerVelocity(Vector3 additiveVelocity) {
vel += additiveVelocity;
}
public void SetPlayerVelocity(Vector3 newVelocity)
{
vel = newVelocity;
}
//Camera
private void Rotate()
{
@@ -163,9 +219,11 @@ public class PlayerMovement : MonoBehaviour
camRotation.x -= Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
camRotation.x = Mathf.Clamp(camRotation.x, minAngle, maxAngle);
cam.localEulerAngles = camRotation;
cam.transform.localEulerAngles = camRotation;
}
//REMOVE WHEN UNNECCESARY
//Respawns player if they fall below a certain point
private void Respawn(){
@@ -174,5 +232,118 @@ public class PlayerMovement : MonoBehaviour
}
}
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void Gravity(){
//Normal Gravity
vel.y -= pStats.PlayerGrav * Time.deltaTime;
//Wallrunning
if (pStats.HasWallrun) { wallRun.WallRunRoutine(); } //adjusted later if we are wallrunning
//If gliding
//Go down slowly
}
void GroundCheck()
{
// Make sure that the ground check distance while already in air is very small, to prevent suddenly snapping to ground
float chosenGroundCheckDistance = isGrounded ? (moveController.skinWidth + groundCheckDistance) : groundCheckDistanceInAir;
// reset values before the ground check
isGrounded = false;
Vector3 groundNormal = Vector3.up;
// only try to detect ground if it's been a short amount of time since last jump; otherwise we may snap to the ground instantly after we try jumping
if (Time.time >= lastTimeJumped + jumpGroundingPreventionTime)
{
// if we're grounded, collect info about the ground normal with a downward capsule cast representing our character capsule
if (Physics.CapsuleCast(GetCapsuleBottomHemisphere(), GetCapsuleTopHemisphere(moveController.height), moveController.radius, Vector3.down, out RaycastHit hit, chosenGroundCheckDistance, groundCheckLayers, QueryTriggerInteraction.Ignore))
{
// storing the upward direction for the surface found
groundNormal = hit.normal;
// Only consider this a valid ground hit if the ground normal goes in the same direction as the character up
// and if the slope angle is lower than the character controller's limit
if (Vector3.Dot(hit.normal, transform.up) > 0f && IsNormalUnderSlopeLimit(groundNormal))
{
isGrounded = true;
// handle snapping to the ground
if (hit.distance > moveController.skinWidth)
{
moveController.Move(Vector3.down * hit.distance);
}
}
}
}
}
private bool IsNormalUnderSlopeLimit(Vector3 normal){ // Returns true if the slope angle represented by the given normal is under the slope angle limit of the character controller
return Vector3.Angle(transform.up, normal) <= moveController.slopeLimit;
}
private Vector3 GetCapsuleBottomHemisphere(){ // Gets the center point of the bottom hemisphere of the character controller capsule
return transform.position + (transform.up * moveController.radius);
}
private Vector3 GetCapsuleTopHemisphere(float atHeight){ // Gets the center point of the top hemisphere of the character controller capsule
return transform.position + (transform.up * (atHeight - moveController.radius));
}
//ADJUST SO DISTANCE IS DETERMINED BY SCROLL WHEEL
//blinks the player forwards
private void Blink(){
if (Input.GetMouseButton(1)){
// Finding the origin and end point of laser.
origin = transform.position + transform.forward * transform.lossyScale.z;
// Finding mouse pos in 3D space.
mousePos = Input.mousePosition;
mousePos.z = 20f;
endPoint = cam.ScreenToWorldPoint(mousePos);
// Find direction of beam.
Vector3 dir = endPoint - origin;
dir.Normalize();
// Are we hitting any colliders?
if (Physics.Raycast(origin, dir, out hit, 20f)){
// If yes, then set endpoint to hit-point.
endPoint = hit.point;
}
// Set end point of laser.
beam.SetPosition(0, origin);
beam.SetPosition(1, endPoint);
// Draw the laser!
beam.enabled = true;
/*Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit raycastHit;
if (Physics.Raycast(ray, out raycastHit, 5.0f)){
LineRenderer.SetPosition(1, raycastHit.point);
}*/
}
else if(!Input.GetMouseButton(1) && beam.enabled == true){
beam.enabled = false;
//disable character controller for a brief second for teleportation
//gameObject.GetComponent<CharacterController>().enabled = false;
//get
Vector3 bump = new Vector3(0, .5f, 0);
//if teleporting due to hit to object, bump them a bit outside normal
if(hit.point != null) {
transform.position = endPoint + hit.normal * 1.25f;
}
//if teleporting in the air or something, just spawn at endpoint
else{
transform.position = endPoint;
}
//reenable character controller
}
}
}

View File

@@ -5,49 +5,49 @@ using UnityEngine;
public class PlayerStats : MonoBehaviour
{
//Maximum possible player speed
private float maxVel;
private float maxVel = 25.0f;
public float MaxVel{
get{ return maxVel; }
set{ maxVel = value; }
}
//Minimum possible player speed
private float minVel;
private float minVel = 2.0f;
public float MinVel{
get{ return minVel; }
set{ minVel = value; }
}
//Current player speed
private float curVel;
private float curVel = 0.0f;
public float CurVel{
get{ return curVel; }
set{ curVel = value; }
}
//Player Jump power
private float acc;
private float acc = 0.1f;
public float Acc{
get{ return acc; }
set{ acc = value; }
}
//Player Jump power
private float jumpPow;
private float jumpPow = 300.0f;
public float JumpPow{
get{ return jumpPow; }
set{ jumpPow = value; }
}
//Players Number of Jumps
private int jumpNum;
private int jumpNum = 2; ////// UPDATE TO 2 WHEN THE JUMP ISSUE IS FIXED
public int JumpNum{
get{ return jumpNum; }
set{ jumpNum = value; }
}
//Player Traction
private float traction;
private float traction = 3.0f;
public float Traction{
get{ return traction; }
set{ traction = value; }
@@ -69,35 +69,35 @@ public class PlayerStats : MonoBehaviour
//MAY BE UNNECCESARY DEPENDING ON HOW GLIDER TURNS OUT
//Gravity Affecting the player
private float playerGrav;
private float playerGrav = 20.0f;
public float PlayerGrav{
get{ return playerGrav; }
set{ playerGrav = value; }
}
//If The Player Has Blink
private bool hasBlink;
private bool hasBlink = false;
public bool HasBlink{
get{ return hasBlink; }
set{ hasBlink = value; }
}
//If The Player Has Glider
private bool hasGlider;
private bool hasGlider = false;
public bool HasGlider{
get{ return hasGlider; }
set{ hasGlider = value; }
}
//If The Player Has Grapple
private bool hasGrapple;
private bool hasGrapple = false;
public bool HasGrapple{
get{ return hasGrapple; }
set{ hasGrapple = value; }
}
//If The Player Has Wallrun
private bool hasWallrun;
private bool hasWallrun = false;
public bool HasWallrun{
get{ return hasWallrun; }
set{ hasWallrun = value; }

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Setup : MonoBehaviour
{
private PlayerStats pstats;
public bool hasWallRun;
[Range( 1, 50)]
public float maxSpeed;
// Start is called before the first frame update
void Start()
{
pstats = this.gameObject.GetComponent<PlayerStats>();
pstats.HasWallrun = hasWallRun;
pstats.MaxVel = maxSpeed;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed382e04d00059e40a6803fa4ad43469
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,189 @@
using UnityEngine;
using System.Linq;
using UnityEngine.Rendering;
[RequireComponent (typeof(PlayerMovement))]
public class WallRun : MonoBehaviour
{
public float wallMaxDistance = 1;
public float wallSpeedMultiplier = 1.2f;
public float minimumHeight = 1.2f;
public float maxAngleRoll = 20;
[Range(0.0f, 1.0f)]
public float normalizedAngleThreshold = 0.1f;
public float jumpDuration = 1;
public float wallBouncing = 3;
public float cameraTransitionDuration = 1;
public float wallGravityDownForce = 20f;
[Space]
PlayerMovement playerMovementController;
Vector3[] directions;
RaycastHit[] hits;
bool isWallRunning = false;
Vector3 lastWallPosition;
Vector3 lastWallNormal;
float elapsedTimeSinceJump = 0;
float elapsedTimeSinceWallAttach = 0;
float elapsedTimeSinceWallDetatch = 0;
bool jumping;
bool isPlayergrounded() => playerMovementController.isGrounded;
public bool IsWallRunning() => isWallRunning;
bool CanWallRun()
{
float verticalAxis = Input.GetAxisRaw("Vertical");
return !isPlayergrounded() && verticalAxis > 0 && VerticalCheck();
}
bool VerticalCheck()
{
return !Physics.Raycast(transform.position, Vector3.down, minimumHeight);
}
void Start()
{
playerMovementController = GetComponent<PlayerMovement>();
directions = new Vector3[]{
Vector3.right,
Vector3.right + Vector3.forward,
Vector3.forward,
Vector3.left + Vector3.forward,
Vector3.left
};
}
public void WallRunRoutine()
{
isWallRunning = false;
if(playerMovementController.GetJumpPressed())
{
jumping = true;
}
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(CanWallRun())
{
hits = hits.ToList().Where(h => h.collider != null).OrderBy(h => h.distance).ToArray();
if(hits.Length > 0)
{
if(hits[0].collider.tag == "WallRun")
{
OnWall(hits[0]);
lastWallPosition = hits[0].point;
lastWallNormal = hits[0].normal;
}
}
}
}
if(isWallRunning)
{
elapsedTimeSinceWallDetatch = 0;
elapsedTimeSinceWallAttach += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * wallGravityDownForce * Time.deltaTime));
}
else
{
elapsedTimeSinceWallAttach = 0;
elapsedTimeSinceWallDetatch += Time.deltaTime;
}
}
bool CanAttach()
{
if(jumping)
{
elapsedTimeSinceJump += Time.deltaTime;
if(elapsedTimeSinceJump > jumpDuration)
{
elapsedTimeSinceJump = 0;
jumping = false;
}
return false;
}
return true;
}
void OnWall(RaycastHit hit){
float d = Vector3.Dot(hit.normal, Vector3.up);
if(d >= -normalizedAngleThreshold && d <= normalizedAngleThreshold)
{
// Vector3 alongWall = Vector3.Cross(hit.normal, Vector3.up);
float vertical = Input.GetAxisRaw("Vertical");
Vector3 alongWall = transform.TransformDirection(Vector3.forward);
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;
moveToSet.y = 0;
playerMovementController.SetPlayerVelocity(moveToSet);
Debug.Log("On Wall");
isWallRunning = true;
}
}
float CalculateSide()
{
if(isWallRunning)
{
Vector3 heading = lastWallPosition - transform.position;
Vector3 perp = Vector3.Cross(transform.forward, heading);
float dir = Vector3.Dot(perp, transform.up);
return dir;
}
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)
{
return lastWallNormal * wallBouncing + Vector3.up;
}
return Vector3.zero;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 535009eaa735a4c4e95c6fc270e32741
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: