mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-04-26 02:00:54 -05:00
slight grapple value adjustment
This commit is contained in:
parent
b2841aa4b9
commit
fb83bff41c
|
|
@ -172,10 +172,10 @@ public class dAerialGrappleAirState : dAerialBaseState
|
|||
Vector3 throwDir = (aSM.hookPoint.transform.position - aSM.stickyHandParent.transform.position).normalized;
|
||||
|
||||
//move the hand
|
||||
aSM.stickyHandParent.GetComponent<CharacterController>().Move(throwDir * 120 * Time.deltaTime);
|
||||
aSM.stickyHandParent.GetComponent<CharacterController>().Move(throwDir * 140 * Time.deltaTime);
|
||||
|
||||
//if the hand approximately reaches the correct point
|
||||
if(Vector3.Distance(aSM.hookPoint.transform.position, aSM.stickyHandParent.transform.position) <= 3f){
|
||||
if(Vector3.Distance(aSM.hookPoint.transform.position, aSM.stickyHandParent.transform.position) <= 4f){
|
||||
|
||||
//Calculate the desired position using current position when hook reaches
|
||||
Vector3 updatedXHookPointDirection = (new Vector3(aSM.transform.position.x, 0, aSM.transform.position.z) - new Vector3(aSM.hookPoint.transform.position.x, 0, aSM.hookPoint.transform.position.z)).normalized;
|
||||
|
|
|
|||
|
|
@ -2,68 +2,98 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AerialGrappleAirState : AerialBaseState
|
||||
public class dAerialGrappleAirState : AerialBaseState
|
||||
{
|
||||
|
||||
Vector3 initialForceDirection;
|
||||
float distanceBeneathHook = -10f; // Distance Beneath Hook
|
||||
float distanceAfterHook = 8f; // Distance After Hook
|
||||
|
||||
float distanceBeneathHook;
|
||||
float distanceAfterHook;
|
||||
Vector3 desiredPosition;
|
||||
Vector3 tempForceDir;
|
||||
Vector3 updatedYHookPoint;
|
||||
Vector3 initialForceDirection; // Initial Force Direction
|
||||
Vector3 desiredPosition; // Desired Player Position
|
||||
Vector3 tempForceDir; // Temporary Force Direction for calculating if the position has been reached
|
||||
Vector3 updatedYHookPoint; // updated y position of the hook
|
||||
|
||||
|
||||
bool pointReached;
|
||||
bool handReached = false;
|
||||
bool pointReached; // Whether the player has reached the desired position
|
||||
bool handReached = false; // Whether the grapple hand has reached
|
||||
|
||||
float initialForcePower;
|
||||
float initialForcePower; // How much force to apply initially
|
||||
|
||||
|
||||
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
|
||||
|
||||
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState)
|
||||
{
|
||||
|
||||
distanceBeneathHook = -10f;
|
||||
distanceAfterHook = 8f;
|
||||
//Reset these Variables
|
||||
pointReached = false;
|
||||
handReached = false;
|
||||
initialForcePower = 120;
|
||||
|
||||
aSM.currentForcePower = initialForcePower;
|
||||
|
||||
//refresh jump number
|
||||
aSM.curJumpNum = 0;
|
||||
aSM.release = false;
|
||||
|
||||
//Calculate the update y position for the hook
|
||||
updatedYHookPoint = new Vector3(aSM.hookPoint.transform.position.x, aSM.hookPoint.transform.position.y - distanceBeneathHook, aSM.hookPoint.transform.position.z);
|
||||
aSM.currentForcePower = initialForcePower;
|
||||
handReached = false;
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
|
||||
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState)
|
||||
{
|
||||
|
||||
//Reset Hand Rotation
|
||||
aSM.stickyHandParent.transform.localEulerAngles = Vector3.zero;
|
||||
|
||||
//Deactivate Visuals
|
||||
aSM.handController.enabled = false;
|
||||
aSM.stickyHandParent.SetActive(false);
|
||||
aSM.lr.enabled = false;
|
||||
|
||||
if(nextState == aSM.GroundedState || nextState == aSM.WallRunState){
|
||||
//if the next state is grounded or wallrun
|
||||
if (nextState == aSM.GroundedState || nextState == aSM.WallRunState)
|
||||
{
|
||||
|
||||
//don't apply the release force
|
||||
aSM.release = false;
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
|
||||
//apply release force
|
||||
aSM.release = true;
|
||||
|
||||
//give the player a slight upwards direction on releasing
|
||||
aSM.pStats.GravVel = 10;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
if(pointReached){
|
||||
//if grounded at when the point is reached then goto grounded state
|
||||
if(aSM.isGrounded){
|
||||
public override void UpdateState(AerialStateManager aSM)
|
||||
{
|
||||
|
||||
//if the player has reached the calculated point
|
||||
if (pointReached)
|
||||
{
|
||||
//if grounded
|
||||
if (aSM.isGrounded)
|
||||
{
|
||||
|
||||
//switch to grounded state
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
else if(!aSM.isGrounded){
|
||||
|
||||
//if isn't grounded
|
||||
else if (!aSM.isGrounded)
|
||||
{
|
||||
|
||||
//switch to falling state
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
//if wallrunning then wallrun
|
||||
else if(aSM.isWallRunning){
|
||||
|
||||
//if wallrunning
|
||||
else if (aSM.isWallRunning)
|
||||
{
|
||||
|
||||
//switch to wallrun state
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
}
|
||||
|
|
@ -71,80 +101,125 @@ public class AerialGrappleAirState : AerialBaseState
|
|||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(AerialStateManager aSM){
|
||||
public override void FixedUpdateState(AerialStateManager aSM)
|
||||
{
|
||||
|
||||
////////ADD A LINE RENDERER WHEN WE GET THE HAND MODEL
|
||||
//Draw Line between player and hookpoint for debug purposes
|
||||
Debug.DrawRay(aSM.transform.position, initialForceDirection); //Visual of line
|
||||
//If the grapple hand hasn't reached
|
||||
if (!handReached)
|
||||
{
|
||||
|
||||
//Apply default gravity
|
||||
if(!handReached){
|
||||
//Throw player hand
|
||||
ThrowStickyHand(aSM);
|
||||
|
||||
//Apply Regular gravity
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
}
|
||||
else if(!pointReached && handReached){
|
||||
|
||||
//If the grapple hand has reached and the player hasn't reached the correct point
|
||||
else if (!pointReached && handReached)
|
||||
{
|
||||
|
||||
//Start Retrieving the grapple hand
|
||||
RetrieveStickyHand(aSM);
|
||||
|
||||
//Move the player using the calculated direction and power
|
||||
aSM.moveController.Move(initialForceDirection * initialForcePower * Time.deltaTime);
|
||||
|
||||
//Disable gravity while moving
|
||||
aSM.GravityCalculation(0);
|
||||
|
||||
//Set Gravity to 0
|
||||
aSM.pStats.GravVel = 0;
|
||||
|
||||
//Calculate A temporary force direction for checking if point is reached
|
||||
tempForceDir = desiredPosition - aSM.transform.position;
|
||||
tempForceDir = tempForceDir.normalized;
|
||||
tempForceDir = new Vector3(tempForceDir.x,0,tempForceDir.z).normalized;
|
||||
tempForceDir = new Vector3(tempForceDir.x, 0, tempForceDir.z).normalized;
|
||||
|
||||
if((aSM.postForceDirection - tempForceDir).magnitude >= .1f && !pointReached){
|
||||
//if the player has approximately reached the right position
|
||||
if ((aSM.postForceDirection - tempForceDir).magnitude >= .1f && !pointReached)
|
||||
{
|
||||
|
||||
//Player has reached the calculated position
|
||||
pointReached = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
//currentForcePower;
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
//normal gravity if grapple is finished
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
}
|
||||
|
||||
if(aSM.stickyHandParent.active){
|
||||
//Offset parent rotation for the hand
|
||||
if (aSM.stickyHandParent.active)
|
||||
{
|
||||
aSM.stickyHandParent.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, aSM.stickyHandParent.transform.parent.rotation.z * -1.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ThrowStickyHand(AerialStateManager aSM){
|
||||
if(!aSM.stickyHandParent.active){
|
||||
//Throw Hand toward hookpoint & calculate desired position
|
||||
public void ThrowStickyHand(AerialStateManager aSM)
|
||||
{
|
||||
|
||||
//If the sticky hand isn't active
|
||||
if (!aSM.stickyHandParent.active)
|
||||
{
|
||||
|
||||
//enable hand
|
||||
aSM.stickyHandParent.SetActive(true);
|
||||
|
||||
//enable line renderer
|
||||
aSM.lr.enabled = true;
|
||||
|
||||
//move hand position to hand
|
||||
aSM.stickyHandParent.transform.position = aSM.handPosition.position;
|
||||
|
||||
//enable the character controller on the hand
|
||||
aSM.handController.enabled = true;
|
||||
}
|
||||
|
||||
aSM.lr.SetPosition(0,aSM.stickyHandParent.transform.position);
|
||||
aSM.lr.SetPosition(1,aSM.handPosition.transform.position);
|
||||
//set positioning for the line renderer
|
||||
aSM.lr.SetPosition(0, aSM.stickyHandParent.transform.position);
|
||||
aSM.lr.SetPosition(1, aSM.handPosition.transform.position);
|
||||
|
||||
Vector3 throwDir = (aSM.hookPoint.transform.position - aSM.stickyHandParent.transform.position).normalized;
|
||||
//Hand Throw Direction
|
||||
Vector3 throwDir = (aSM.hookPoint.transform.position - aSM.stickyHandParent.transform.position).normalized;
|
||||
|
||||
aSM.stickyHandParent.GetComponent<CharacterController>().Move(throwDir * 130 * Time.deltaTime);
|
||||
if(Vector3.Distance(aSM.hookPoint.transform.position, aSM.stickyHandParent.transform.position) <= 3f){
|
||||
//move the hand
|
||||
aSM.stickyHandParent.GetComponent<CharacterController>().Move(throwDir * 140 * Time.deltaTime);
|
||||
|
||||
//if the hand approximately reaches the correct point
|
||||
if (Vector3.Distance(aSM.hookPoint.transform.position, aSM.stickyHandParent.transform.position) <= 4f)
|
||||
{
|
||||
|
||||
//Calculate the desired position using current position when hook reaches
|
||||
Vector3 updatedXHookPointDirection = (new Vector3(aSM.transform.position.x, 0, aSM.transform.position.z) - new Vector3(aSM.hookPoint.transform.position.x, 0, aSM.hookPoint.transform.position.z)).normalized;
|
||||
|
||||
desiredPosition = updatedYHookPoint + (updatedXHookPointDirection * -distanceAfterHook);
|
||||
//rope length limit
|
||||
desiredPosition = updatedYHookPoint + (updatedXHookPointDirection * -distanceAfterHook);
|
||||
initialForceDirection = desiredPosition - aSM.transform.position;
|
||||
initialForceDirection = initialForceDirection.normalized;
|
||||
aSM.postForceDirection = new Vector3(initialForceDirection.x, 0, initialForceDirection.z).normalized;
|
||||
|
||||
aSM.postForceDirection = new Vector3(initialForceDirection.x, 0, initialForceDirection.z).normalized;
|
||||
//Hand has Reached
|
||||
handReached = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void RetrieveStickyHand(AerialStateManager aSM){
|
||||
aSM.lr.SetPosition(0,aSM.stickyHandParent.transform.position);
|
||||
aSM.lr.SetPosition(1,aSM.handPosition.transform.position);
|
||||
//Retrieve Grapple Hand
|
||||
public void RetrieveStickyHand(AerialStateManager aSM)
|
||||
{
|
||||
aSM.lr.SetPosition(0, aSM.stickyHandParent.transform.position);
|
||||
aSM.lr.SetPosition(1, aSM.handPosition.transform.position);
|
||||
|
||||
Vector3 catchDir = (aSM.handPosition.transform.position - aSM.stickyHandParent.transform.position).normalized;
|
||||
if(Vector3.Distance(aSM.handPosition.transform.position, aSM.stickyHandParent.transform.position) > .5f){
|
||||
Vector3 catchDir = (aSM.handPosition.transform.position - aSM.stickyHandParent.transform.position).normalized;
|
||||
if (Vector3.Distance(aSM.handPosition.transform.position, aSM.stickyHandParent.transform.position) > .5f)
|
||||
{
|
||||
aSM.stickyHandParent.GetComponent<CharacterController>().Move(catchDir * 30 * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ EditorUserSettings:
|
|||
value: 22424703114646680e0b0227036c7c1f18030a25203b68252320092a
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-5:
|
||||
value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26
|
||||
value: 22424703114646680e0b0227036c7c1f18030a25203b68252320092a
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-6:
|
||||
value: 22424703114646680e0b0227036c7c1f18030a25203b68252320092a
|
||||
value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-7:
|
||||
value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb
|
||||
|
|
@ -33,7 +33,7 @@ EditorUserSettings:
|
|||
value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-9:
|
||||
value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb
|
||||
value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26
|
||||
flags: 0
|
||||
vcSharedLogLevel:
|
||||
value: 0d5e400f0650
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user