From 946e2146a3369cb168b879d46b67d41493d3c9a9 Mon Sep 17 00:00:00 2001 From: Melbyj1125 <60886701+Melbyj1125@users.noreply.github.com> Date: Fri, 10 Dec 2021 22:36:40 -0600 Subject: [PATCH 1/2] grapple still doesn't work fixed some other values with prefabs --- Assets/New Terrain.asset | Bin 0 -> 557472 bytes Assets/New Terrain.asset.meta | 8 ++ Assets/Scenes/Demos/MovementScene.unity | 92 +++++++++++++++++- Assets/Scripts/KingAbilities/Bumper.cs | 2 +- .../DebugPlayer/DebugItems/dGrapplingHook.cs | 84 +++++++++++++--- .../DebugPlayer/dPlayerMovement.cs | 9 +- .../PlayerItems/ItemScripts/GrapplingHook.cs | 74 ++++++++++++-- .../Scripts/PlayerScripts/PlayerMovement.cs | 67 ++++++------- 8 files changed, 269 insertions(+), 67 deletions(-) create mode 100644 Assets/New Terrain.asset create mode 100644 Assets/New Terrain.asset.meta diff --git a/Assets/New Terrain.asset b/Assets/New Terrain.asset new file mode 100644 index 0000000000000000000000000000000000000000..db573109e36cc77e33fa0449c72e46cf22b43490 GIT binary patch literal 557472 zcmeI)TZ|;vSqJdy*^3>ATnHpMIKak)yK!u92sjvf*1PN2VK=*YH<$on>6vNowA0fw z>F%+2Ng$m7&IOVhTVnR@x=4?W+s-TGqlT~+tob4SM zdmq2M`tNJkuJwA6JeTRUYp=Zbjb~r+mET?c!`J-L7mnWdsgM3vwBB~Os&bPo-(OYp z*yUQiGOz2p>ctknbEumCL9d#}=JodNKDj~WUlZS_4_EX2Ua8xnDy0`K{}6rO9_zXP zq4-2sQ8y*?JEQ;aiPf9q(~L21!l<+Vx5Rh9^navo+lwRZ_J6d_=X)D0_J7k--m9Ko zspgZ?f6k$MeBJ(EwzPkD{T=L|GN0@=7&1R|Mi)#Mpa6$I@~$_*G7By{2Z=6 z5p8+=d3<@Jbn_#f>+c)td>(aEdexE6^>=GDFCKr+|M_Uo`M*B%c~qtJs_y*1G1_l5 z|JyQecdnNY*XO65{~MO_?)<;0&gW4#WpV!B9LsUS7SZ%ywAIN*XLU^e=(|37SHdSqJ97PnIDRV z^vV9eE%SNVx!(3jeSN(uw#oe4m-3^X>+3r*UyZ7iUUgIF`ufgj?~Z>{^?aQF_Wt^= zrMwyc4Q2fA&U_wKDZQ#Yem>`JH2xi#w>#I%-SNM7DR1ttJIeTXW`Eo9{$@}k~rTl2;{ySdh^QfB=KArn7 zpY`4A_egzzyu0-OeRW=Tu9v(0zjbN5~880r@i}zwdzjxsw0Tb@CsL`NjLC%4hfeb$%@Brlju+k^gbo z|AA=kRmV!2%T4|#C0{)t|I?D6I3WL0$sb(Gk5oCo7bDO4om|Sh^E-7w-p=pz0eL&W zhYrZw`MrH9Z_e*ul=(kg=TViC=Qp39UoLsRM`LlXwD~`k{2fbq^ZVgHO8&zK*VS8>d4dYY@HvAx+!sgch2uSqq%#2o4oZqcR=3yoj)LN{o=RALjNoE_{Ylp zAFcDKO3C-b3o-wZYX6 z{@<66MRPY_sj~kMm;QgO&dbjAa<~6?FYVv$|Hqf|rvJ~C{(qv*qbeomm)BQ2|9r-F z=hyB3Jxh7>{QqL~pYOk)%6uMGDT~kl{H=DQ=l@SJEHGA|M}beeM@=s z{(oC+llSLjDeu0Yr*%G$x+!`5`|ro5P- zU7X(wF@9cud4GIzDQ|rKri}lo%;!;+vgq?nwBKm_PiNllTrVH4-|y}Czp|7!zkmKU z#?SeE=79XGCI9So@_fIn#Ljtt{c4>bi@GT>|9brP{qk$k+^oX8{Njp2F($Bzv+W}DSk|4LaHjvpQjFK^DWsVt4Rhtt7@oynlTQEhII z1{Vj@*`xi9;qJ8B9P~%C&8sK3N86Klk6y0U;@8&3q%@4OqhNWczaHnWnheGpgUQ+L zjX||L9h`5cb#^d~3FL`f-#od!JC327l?(l?olzXnWBn(G;5~qLb(%IqoZ2wAq zqMKo|%g#M>X7J=-l&uZR-jo~Z{2^8zMe~>aTfNd&|G0T`yV!YF)&KFhO>(H+N!&(n z-W?BTS1+yY4o9=$_)nhoVEY} literal 0 HcmV?d00001 diff --git a/Assets/New Terrain.asset.meta b/Assets/New Terrain.asset.meta new file mode 100644 index 0000000..9ae68f4 --- /dev/null +++ b/Assets/New Terrain.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d879c807dc45e714892ef692f67c4254 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 15600000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Demos/MovementScene.unity b/Assets/Scenes/Demos/MovementScene.unity index ae1d434..29d297b 100644 --- a/Assets/Scenes/Demos/MovementScene.unity +++ b/Assets/Scenes/Demos/MovementScene.unity @@ -520,6 +520,82 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 478416584} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &581642405 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 581642408} + - component: {fileID: 581642407} + - component: {fileID: 581642406} + m_Layer: 0 + m_Name: Terrain + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 4294967295 + m_IsActive: 1 +--- !u!154 &581642406 +TerrainCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 581642405} + m_Material: {fileID: 0} + m_Enabled: 1 + m_TerrainData: {fileID: 15600000, guid: d879c807dc45e714892ef692f67c4254, type: 2} + m_EnableTreeColliders: 1 +--- !u!218 &581642407 +Terrain: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 581642405} + m_Enabled: 1 + serializedVersion: 6 + m_TerrainData: {fileID: 15600000, guid: d879c807dc45e714892ef692f67c4254, type: 2} + m_TreeDistance: 5000 + m_TreeBillboardDistance: 50 + m_TreeCrossFadeLength: 5 + m_TreeMaximumFullLODCount: 50 + m_DetailObjectDistance: 80 + m_DetailObjectDensity: 1 + m_HeightmapPixelError: 5 + m_SplatMapDistance: 1000 + m_HeightmapMaximumLOD: 0 + m_ShadowCastingMode: 2 + m_DrawHeightmap: 1 + m_DrawInstanced: 0 + m_DrawTreesAndFoliage: 1 + m_ReflectionProbeUsage: 1 + m_MaterialTemplate: {fileID: 10652, guid: 0000000000000000f000000000000000, type: 0} + m_BakeLightProbesForTrees: 1 + m_PreserveTreePrototypeLayers: 0 + m_DeringLightProbesForTrees: 1 + m_ScaleInLightmap: 0.0256 + m_LightmapParameters: {fileID: 15203, guid: 0000000000000000f000000000000000, type: 0} + m_GroupingID: 0 + m_RenderingLayerMask: 1 + m_AllowAutoConnect: 1 +--- !u!4 &581642408 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 581642405} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 8 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &724425600 GameObject: m_ObjectHideFlags: 0 @@ -1078,6 +1154,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 471283137481508403, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: propelPower + value: 50 + objectReference: {fileID: 0} - target: {fileID: 5633209979457551608, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} propertyPath: m_Name value: DebugPlayerPrefab @@ -1126,6 +1206,14 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 7058615058147771192, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_IsKinematic + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7058615058147771192, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_CollisionDetection + value: 3 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} --- !u!1 &1257935739 @@ -1407,8 +1495,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1405946429} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.5, y: 23.9, z: 10.3} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalPosition: {x: -9.8, y: 18.3, z: 10.3} + m_LocalScale: {x: 10, y: 10, z: 10} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 6 diff --git a/Assets/Scripts/KingAbilities/Bumper.cs b/Assets/Scripts/KingAbilities/Bumper.cs index 46fb3dd..57f8fab 100644 --- a/Assets/Scripts/KingAbilities/Bumper.cs +++ b/Assets/Scripts/KingAbilities/Bumper.cs @@ -9,7 +9,7 @@ public class Bumper : MonoBehaviour { // Is called whenever something collides with the bumper void OnTriggerEnter(Collider objectHit) { if (objectHit.tag == "Player") {//Checks if the other object is the player - dPlayerMovement playerMovement = objectHit.GetComponent(); + PlayerMovement playerMovement = objectHit.GetComponent(); float DirBumpX = playerMovement.driftVel.x * -1;//Inverts the Player Velocity x float DirBumpY = .1f; diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs index baba641..10cc33d 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs @@ -5,7 +5,7 @@ using UnityEngine; public class dGrapplingHook : NetworkBehaviour { - public float maxGrappleDistance = 25; + public float maxGrappleDistance = 25; public bool isGrappled; private int hookPointIndex; @@ -16,14 +16,13 @@ public class dGrapplingHook : NetworkBehaviour private CharacterController movementController; private dPlayerMovement playerMovement; private PlayerStats pStats; - private Vector3 hookLerp; - public float ropeLength; + [SerializeField] private float ropeLength; private float climbRate = 5; // Start is called before the first frame update void Start() { - isGrappled = false; + isGrappled = false; hookPoints = GameObject.FindGameObjectsWithTag("HookPoint"); movementController = gameObject.GetComponent(); playerMovement = gameObject.GetComponent(); @@ -35,7 +34,6 @@ public class dGrapplingHook : NetworkBehaviour { //if (!IsLocalPlayer) { return; } - //if E or left face gamepad button is pressed is slightly pressed if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit { if (!isGrappled) //If we are not grappling @@ -47,7 +45,7 @@ public class dGrapplingHook : NetworkBehaviour ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f; isGrappled = true; //toggle grappling state } - } + } else //Else we are grappling { //physics tear down? @@ -62,7 +60,6 @@ public class dGrapplingHook : NetworkBehaviour { Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line - //if left shift or left bumper held down if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.JoystickButton4)) //Extend hook { ropeLength += climbRate * Time.deltaTime; @@ -82,24 +79,23 @@ public class dGrapplingHook : NetworkBehaviour //Debug.Log(ropeLength.ToString()); } //Do grappling physics based on hookPoint - if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength) + if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength ) { - movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * Time.deltaTime); - //Character controller move? - //movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * ropeLength * 10 *Time.deltaTime); - //Lerp? or another smoother way? Better physics? Wait until refinement to deal with + //Impact Based + Debug.Log("y"); + playerMovement.g = 2; + movementController.Move((hookPoint.transform.position - gameObject.transform.position) * Time.deltaTime); + } } - if(playerMovement.GetJumpPressed()){ - isGrappled = false; - } + if(playerMovement.GetJumpPressed()) isGrappled = false; } int FindHookPoint() { float least = maxGrappleDistance; int index = -1; - for (int i = 0; i < hookPoints.Length; i++) + for(int i = 0; i(); + // playerMovement = gameObject.GetComponent(); + // pStats = gameObject.GetComponent(); + // cam = playerMovement.cam; + // } + + // private void FixedUpdate() + // { + // getGrapplePoint(); + // //Debug.Log((hookPoint.transform.position - transform.position).normalized); + // if (isGrappled && !Input.GetKeyDown(KeyCode.E)) + // { + // //playerMovement.AddImpact((hookPoint - transform.position), propelPower); + // forwardHookLerp = Vector3.Lerp(forwardHookLerp, transform.forward * 50, .03f); + // movementController.Move(forwardHookLerp * Time.deltaTime); + + // upwardsHookLerp = Vector3.Lerp(upwardsHookLerp, (hookPoint - transform.position).normalized * Vector3.Distance(transform.position, hookPoint) * propelPower, .03f); + // movementController.Move(upwardsHookLerp * Time.deltaTime); + // isGrappled = false; + // } + // } + + // private void getGrapplePoint(){ + // //if E or left face gamepad button is pressed is slightly pressed + // if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit + // { + // if (!isGrappled) //If we are not grappling + // { + // if(Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit raycastHit)){ + // if(raycastHit.collider.gameObject.transform.tag == "HookPoint"){ + // isGrappled = true; + // hookPoint = new Vector3 (raycastHit.point.x,raycastHit.point.y,raycastHit.point.z); + // } + // } + // } + // } + // } } diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs index 0b73d04..1ff33dc 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs @@ -32,7 +32,7 @@ public class dPlayerMovement : NetworkBehaviour float curCoyJumpTimer; // current Coyote Jump time public float lowJumpMultiplier; // Short jump multiplier public float fallMultiplier; // High Jump Multiplier - private float g = 0; // the y velocity + public float g = 0; // the y velocity //Glide Values bool tempSet = false; @@ -99,7 +99,7 @@ public class dPlayerMovement : NetworkBehaviour moveController = GetComponent(); // Character Controller rB = GetComponent(); //Rigid Body capCol = GetComponent(); // Capsule Collider - capCol.enabled = false; + capCol.enabled = true; parentObj = transform.parent.gameObject; animator = GetComponent(); @@ -296,6 +296,8 @@ public class dPlayerMovement : NetworkBehaviour //if jump is being held coyote timer is zero if(jumpHeld) curCoyJumpTimer = 0; + if(grapple.isGrappled && curJumpNum == 2) curJumpNum = 1; + //If space/south face gamepad button isn't being pressed then jump is false if (Input.GetAxis("Jump") == 0){ jumpHeld = false; @@ -438,10 +440,9 @@ public class dPlayerMovement : NetworkBehaviour } //apply gravity if not grounded and coyote timer is less than 0 - if((isGrounded == false && curCoyJumpTimer <= 0) || (!grapple.isGrappled && isGrounded == false)){ + if(isGrounded == false && curCoyJumpTimer <= 0){ g -= grav * Time.deltaTime; } - //else don't apply gravity else{ g = 0; diff --git a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs index 7282046..9d2a6bf 100644 --- a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs +++ b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs @@ -5,9 +5,9 @@ using UnityEngine; public class GrapplingHook : NetworkBehaviour { - public float maxGrappleDistance = 25; + public float maxGrappleDistance = 25; - private bool isGrappled; + public bool isGrappled; private int hookPointIndex; private GameObject hookPoint; private GameObject[] hookPoints; @@ -16,7 +16,7 @@ public class GrapplingHook : NetworkBehaviour private CharacterController movementController; private PlayerMovement playerMovement; private PlayerStats pStats; - private float ropeLength; + [SerializeField] private float ropeLength; private float climbRate = 5; // Start is called before the first frame update @@ -56,6 +56,7 @@ public class GrapplingHook : NetworkBehaviour private void FixedUpdate() { + if (!IsLocalPlayer) { return; } if (isGrappled) { Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line @@ -79,15 +80,16 @@ public class GrapplingHook : NetworkBehaviour //Debug.Log(ropeLength.ToString()); } //Do grappling physics based on hookPoint - if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength) + if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength ) { //Impact Based - playerMovement.AddImpact((hookPoint.transform.position - gameObject.transform.position), pStats.PlayerGrav); - //Character controller move? - //movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * ropeLength*Time.deltaTime); - //Lerp? or another smoother way? Better physics? Wait until refinement to deal with + Debug.Log("y"); + playerMovement.g = 2; + movementController.Move((hookPoint.transform.position - gameObject.transform.position) * Time.deltaTime); + } } + if(playerMovement.GetJumpPressed()) isGrappled = false; } int FindHookPoint() @@ -104,4 +106,60 @@ public class GrapplingHook : NetworkBehaviour } return index; } + ///////////Hookshot Concept + // public float maxGrappleDistance = 25; + + // public bool isGrappled; + // private Vector3 hookPoint; + // private float distance; + // public float propelPower = 100; + + // private CharacterController movementController; + // private dPlayerMovement playerMovement; + // private PlayerStats pStats; + // private Camera cam; + // private Vector3 forwardHookLerp; + // private Vector3 upwardsHookLerp; + + // // Start is called before the first frame update + // void Start() + // { + // isGrappled = false; + // movementController = gameObject.GetComponent(); + // playerMovement = gameObject.GetComponent(); + // pStats = gameObject.GetComponent(); + // cam = playerMovement.cam; + // } + + // private void FixedUpdate() + // { + // getGrapplePoint(); + // //Debug.Log((hookPoint.transform.position - transform.position).normalized); + // if (isGrappled && !Input.GetKeyDown(KeyCode.E)) + // { + // //playerMovement.AddImpact((hookPoint - transform.position), propelPower); + // forwardHookLerp = Vector3.Lerp(forwardHookLerp, transform.forward * 50, .03f); + // movementController.Move(forwardHookLerp * Time.deltaTime); + + // upwardsHookLerp = Vector3.Lerp(upwardsHookLerp, (hookPoint - transform.position).normalized * Vector3.Distance(transform.position, hookPoint) * propelPower, .03f); + // movementController.Move(upwardsHookLerp * Time.deltaTime); + // isGrappled = false; + // } + // } + + // private void getGrapplePoint(){ + // //if E or left face gamepad button is pressed is slightly pressed + // if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit + // { + // if (!isGrappled) //If we are not grappling + // { + // if(Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit raycastHit)){ + // if(raycastHit.collider.gameObject.transform.tag == "HookPoint"){ + // isGrappled = true; + // hookPoint = new Vector3 (raycastHit.point.x,raycastHit.point.y,raycastHit.point.z); + // } + // } + // } + // } + // } } diff --git a/Assets/Scripts/PlayerScripts/PlayerMovement.cs b/Assets/Scripts/PlayerScripts/PlayerMovement.cs index 6ab3b78..5bb34c7 100644 --- a/Assets/Scripts/PlayerScripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerScripts/PlayerMovement.cs @@ -6,7 +6,6 @@ using UnityEngine.UI; public class PlayerMovement : NetworkBehaviour { - //Controller object //Scripts public PlayerStats pStats; @@ -17,8 +16,7 @@ public class PlayerMovement : NetworkBehaviour private Vector3 moveZ; private Vector3 moveX; - private Vector3 driftVel; - private Vector3 lerpY; + public Vector3 driftVel; //Player prefab private GameObject parentObj; @@ -29,11 +27,11 @@ public class PlayerMovement : NetworkBehaviour //Jump value public int curJumpNum; // current Jumps used private bool jumpHeld; // Is jump being held - float coyJumpTimer = 0.2f; // Default Coyote Jump time + float coyJumpTimer = 0.1f; // Default Coyote Jump time float curCoyJumpTimer; // current Coyote Jump time public float lowJumpMultiplier; // Short jump multiplier public float fallMultiplier; // High Jump Multiplier - private float g = 0; // the y velocity + public float g = 0; // the y velocity //Glide Values bool tempSet = false; @@ -44,7 +42,6 @@ public class PlayerMovement : NetworkBehaviour private Vector3 impact = Vector3.zero; private float distToGround; - //Wallrunning private WallRun wallRun; @@ -73,14 +70,14 @@ public class PlayerMovement : NetworkBehaviour private Rigidbody rB; private CapsuleCollider capCol; private bool firstHit = false; - //private bool heldDown = false; //Variable for testing ragdoll reenable if needed + //private bool heldDown = false; //Variable for testing Ragdoll reenable if needed private bool beginRagTimer = false; private float ragTime; private Vector3 prevRot; private Vector3 hitForce; //Slide Variables - private bool isSliding = false; + public bool isSliding = false; private float originalTraction; private RaycastHit ray; private Vector3 up; @@ -89,6 +86,9 @@ public class PlayerMovement : NetworkBehaviour //Blink private Blink blink; + private GrapplingHook grapple; + + //Animation controller Animator animator; @@ -98,7 +98,7 @@ public class PlayerMovement : NetworkBehaviour moveController = GetComponent(); // Character Controller rB = GetComponent(); //Rigid Body capCol = GetComponent(); // Capsule Collider - capCol.enabled = false; + capCol.enabled = true; parentObj = transform.parent.gameObject; animator = GetComponent(); @@ -106,22 +106,22 @@ public class PlayerMovement : NetworkBehaviour pStats = GetComponent(); // PlayerStats wallRun = GetComponent(); //Wallrun blink = GetComponent(); //Blink + grapple = GetComponent(); //Get parents up direction up = GetComponentInParent().up; - +// //Coyote Timer Initialization curCoyJumpTimer = coyJumpTimer; } - - void Start() { distToGround = GetComponent().bounds.extents.y; // Don't do movement unless this is the local player controlling it // Otherwise we let the server handle moving us + if (!IsLocalPlayer) { return; } // Don't lock the cursor multiple times if this isn't the local player @@ -130,8 +130,6 @@ public class PlayerMovement : NetworkBehaviour Cursor.lockState = CursorLockMode.Locked; } - - // Update is called once per frame void FixedUpdate() { @@ -167,10 +165,8 @@ public class PlayerMovement : NetworkBehaviour g -= pStats.PlayerGrav * Time.deltaTime; rB.AddForce(new Vector3(0,g,0)); } - - //TEMP FOR TESTING - //Checks if player should respawn - //Respawn(); + Respawn(); + } @@ -200,6 +196,7 @@ public class PlayerMovement : NetworkBehaviour //Slide Function Slide(); + //move animation //if vel from input is greater than 0, start sprinting animation if (PlayerSpeed() > 0.1) @@ -209,8 +206,9 @@ public class PlayerMovement : NetworkBehaviour if(animator != null) animator.SetBool("isRunning", true); } //if low enough movement from player (this will be still at this value) stop animation - else if (driftVel.magnitude < .510f) + else if (driftVel.magnitude < .05f) { + driftVel = Vector3.zero; if(animator != null) animator.SetBool("isRunning", false); } @@ -229,21 +227,18 @@ public class PlayerMovement : NetworkBehaviour pStats.CurVel = 0.0f; return pStats.CurVel; } - //If current speed is below min when pressed set to minimum speed else if (pStats.CurVel < pStats.MinVel) { pStats.CurVel = pStats.MinVel; return pStats.MinVel; } - // while the speed is below max speed slowly increase it else if ((pStats.CurVel >= pStats.MinVel) && (pStats.CurVel < pStats.MaxVel)) { pStats.CurVel += pStats.Acc; return pStats.CurVel; } - //If the players speed is above or equal to max speed set speed to max else { @@ -257,7 +252,7 @@ public class PlayerMovement : NetworkBehaviour //Apply Impact for when force needs to be applied without ragdolling public void AddImpact(Vector3 dir, float force) { - if (!IsLocalPlayer) { return; } + //if (!IsLocalPlayer) { return; } //Normalize direction multiply by force and add it to the impact dir.Normalize(); @@ -274,7 +269,7 @@ public class PlayerMovement : NetworkBehaviour if (Input.GetAxis("Jump") != 0 && !jumpHeld && curJumpNum < pStats.JumpNum && !isSliding) { if(wallRun.IsWallRunning()){ - AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 20f); + AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 10f); g = pStats.JumpPow; } @@ -290,7 +285,7 @@ public class PlayerMovement : NetworkBehaviour lastTimeJumped = Time.time; //If grounded no jumps have been used and coyote Timer is refreshed - if(isGrounded){ + if(isGrounded && g == 0){ curCoyJumpTimer = coyJumpTimer; curJumpNum = 0; } @@ -300,14 +295,14 @@ public class PlayerMovement : NetworkBehaviour //if jump is being held coyote timer is zero if(jumpHeld) curCoyJumpTimer = 0; + if(grapple.isGrappled && curJumpNum == 2) curJumpNum = 1; + //If space/south face gamepad button isn't being pressed then jump is false if (Input.GetAxis("Jump") == 0){ jumpHeld = false; } } - - //Get and update PlayerValues for other scripts //Get jumpHeld public bool GetJumpPressed(){ @@ -380,7 +375,7 @@ public class PlayerMovement : NetworkBehaviour { if (transform.position.y < -5) { - transform.position = new Vector3(1f, 3f, 1f); + TeleportPlayer(new Vector3(0,100,0)); } } @@ -435,22 +430,21 @@ public class PlayerMovement : NetworkBehaviour private void GravityCalculation(float grav){ //apply slight upwards force for jump smoothing when g < 0 if(g < 0){ - g += grav * (fallMultiplier - 1) * Time.deltaTime; + g += grav * (fallMultiplier - 1) * Time.deltaTime; } //apply smaller upwards force if jump is released early when jumping creating a short jump else if (g > 0 && !Input.GetButton("Jump")){ - g += grav * (lowJumpMultiplier - 1) * Time.deltaTime; + g += grav * (lowJumpMultiplier - 1) * Time.deltaTime; } //apply gravity if not grounded and coyote timer is less than 0 - if((isGrounded == false && curCoyJumpTimer <= 0)){ - g -= grav * Time.deltaTime; + if(isGrounded == false && curCoyJumpTimer <= 0){ + g -= grav * Time.deltaTime; } - //else don't apply gravity else{ - g = 0; + g = 0; } } @@ -472,7 +466,7 @@ public class PlayerMovement : NetworkBehaviour { isGrounded = true; // handle snapping to the ground - if (groundHit.distance > moveController.skinWidth) + if (groundHit.distance > moveController.skinWidth && !grapple.isGrappled) { moveController.Move(Vector3.down * groundHit.distance); } @@ -504,6 +498,7 @@ public class PlayerMovement : NetworkBehaviour rB.isKinematic = true; rB.detectCollisions = false; transform.localEulerAngles = prevRot; + CancelMomentum(); } //When to begin the ragdoll timer @@ -566,7 +561,7 @@ public class PlayerMovement : NetworkBehaviour vel = Vector3.zero; moveX = Vector3.zero; moveZ = Vector3.zero; - moveController.enabled = false; + driftVel = Vector3.zero; } private IEnumerator RespawnTimer() From e8710ba6d97379bee95d2ff6f96a1aea8b443249 Mon Sep 17 00:00:00 2001 From: Melbyj1125 <60886701+Melbyj1125@users.noreply.github.com> Date: Fri, 10 Dec 2021 22:38:46 -0600 Subject: [PATCH 2/2] Updated player prefabs they use continuous rigid body now --- Assets/Prefabs/Player/DebugPlayerPrefab.prefab | 7 ++++++- Assets/Prefabs/Player/PlayerPrefab.prefab | 7 ++++++- Assets/Scripts/KingAbilities/Bumper.cs | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Assets/Prefabs/Player/DebugPlayerPrefab.prefab b/Assets/Prefabs/Player/DebugPlayerPrefab.prefab index b2c6c33..8e76aa5 100644 --- a/Assets/Prefabs/Player/DebugPlayerPrefab.prefab +++ b/Assets/Prefabs/Player/DebugPlayerPrefab.prefab @@ -343,7 +343,7 @@ Rigidbody: m_IsKinematic: 1 m_Interpolate: 0 m_Constraints: 0 - m_CollisionDetection: 0 + m_CollisionDetection: 3 --- !u!136 &3559681995605743320 CapsuleCollider: m_ObjectHideFlags: 0 @@ -438,15 +438,18 @@ MonoBehaviour: m_EditorClassIdentifier: pStats: {fileID: 0} vel: {x: 0, y: 0, z: 0} + driftVel: {x: 0, y: 0, z: 0} curJumpNum: 0 lowJumpMultiplier: 0.3 fallMultiplier: 1.5 + g: 0 isGrounded: 0 groundCheckDistance: 0.05 cam: {fileID: 4654986889578046791} minAngle: -30 maxAngle: 45 sensitivity: 200 + isSliding: 0 --- !u!114 &4788888989419098570 MonoBehaviour: m_ObjectHideFlags: 0 @@ -474,6 +477,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: maxGrappleDistance: 25 + isGrappled: 0 + ropeLength: 0 --- !u!114 &5784126162129930074 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Player/PlayerPrefab.prefab b/Assets/Prefabs/Player/PlayerPrefab.prefab index c7aad01..9070625 100644 --- a/Assets/Prefabs/Player/PlayerPrefab.prefab +++ b/Assets/Prefabs/Player/PlayerPrefab.prefab @@ -152,15 +152,18 @@ MonoBehaviour: m_EditorClassIdentifier: pStats: {fileID: 0} vel: {x: 0, y: 0, z: 0} + driftVel: {x: 0, y: 0, z: 0} curJumpNum: 0 lowJumpMultiplier: 0.3 fallMultiplier: 1.5 + g: 0 isGrounded: 0 groundCheckDistance: 0.05 cam: {fileID: 7188906082643956516} minAngle: -30 maxAngle: 45 sensitivity: 301 + isSliding: 0 --- !u!114 &273103334658887749 MonoBehaviour: m_ObjectHideFlags: 0 @@ -224,6 +227,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: maxGrappleDistance: 25 + isGrappled: 0 + ropeLength: 0 --- !u!114 &2356773567935625033 MonoBehaviour: m_ObjectHideFlags: 0 @@ -265,7 +270,7 @@ Rigidbody: m_IsKinematic: 1 m_Interpolate: 0 m_Constraints: 0 - m_CollisionDetection: 0 + m_CollisionDetection: 3 --- !u!136 &3772338269032432186 CapsuleCollider: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/KingAbilities/Bumper.cs b/Assets/Scripts/KingAbilities/Bumper.cs index 57f8fab..d0089d2 100644 --- a/Assets/Scripts/KingAbilities/Bumper.cs +++ b/Assets/Scripts/KingAbilities/Bumper.cs @@ -19,6 +19,7 @@ public class Bumper : MonoBehaviour { DirBump = Vector3.Normalize(DirBump);//Normalizes the vector to be used as a bump direction playerMovement.GetHit(DirBump, bumpPower); + // } } }