Can move up and down on rope

Change boosting technique
This commit is contained in:
Soulaha Balde 2022-10-19 21:35:22 -04:00
parent 5b7c6ab2e6
commit c079a6ccba
11 changed files with 81 additions and 24 deletions

View File

@ -6,25 +6,36 @@ using UnityEngine.UI;
public class GrappleHook : MonoBehaviour
{
[Header("Grapple settings")]
[SerializeField]
private float maxGrappleDist = 200;
[SerializeField]
private float grappleExtendSpeed = 20;
private float grappleExtensionSpeed = 10;
[SerializeField]
private float grappleStrength = 4.5f * 5f;
[SerializeField]
private float grappleDamper = 7f;
[SerializeField]
private float grappleBoostSpeed = 50f;
[SerializeField]
private float grappleDrawingSpeed = 20;
[SerializeField]
private LayerMask grappleableLayer;
[Header("References")]
[SerializeField]
private Transform gunPos;
private Vector3 hitPosLocal;
private SpringJoint joint;
private LineRenderer lr;
RaycastHit hit;
private bool grappled = false;
private Vector3 currGrappleEndPos;
[SerializeField]
private RectTransform canvasRect;
[SerializeField]
private RectTransform hitMarkerRect;
// Start is called before the first frame update
private Vector3 hitPosLocal;
private SpringJoint joint;
private LineRenderer lr;
RaycastHit hit;
private bool grappled = false, boosted = false;
private Vector3 currGrappleEndPos;
void Start()
{
lr = gameObject.GetComponentInChildren<LineRenderer>();
@ -32,7 +43,7 @@ public class GrappleHook : MonoBehaviour
hitMarkerRect.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
@ -42,14 +53,22 @@ public class GrappleHook : MonoBehaviour
if(grappled){
DrawRope(Time.deltaTime);
if(Input.GetMouseButtonDown(1)){
joint.minDistance = 0f;
joint.maxDistance = 0f;
boosted = true;
}
if(boosted){
joint.maxDistance -= grappleBoostSpeed * Time.deltaTime;
}
// TODO extend and retract rope
if(Input.GetKey(KeyCode.W)){
ChangeGrappleLength(-grappleExtensionSpeed * Time.deltaTime);
}else if(Input.GetKey(KeyCode.S)){
ChangeGrappleLength(grappleExtensionSpeed * Time.deltaTime);
}
return;
}
Aim();
// TODO extend and retract rope
}
private void Aim(){
@ -84,7 +103,7 @@ public class GrappleHook : MonoBehaviour
}else{
endPoint = hit.point;
}
currGrappleEndPos = Vector3.Lerp(currGrappleEndPos, endPoint, deltaTime * grappleExtendSpeed);
currGrappleEndPos = Vector3.Lerp(currGrappleEndPos, endPoint, deltaTime * grappleDrawingSpeed);
lr.SetPosition(1, currGrappleEndPos);
if(!lr.enabled)lr.enabled = true;
@ -99,8 +118,7 @@ public class GrappleHook : MonoBehaviour
joint = gameObject.AddComponent<SpringJoint>();
joint.anchor = transform.InverseTransformPoint(gunPos.position);
joint.autoConfigureConnectedAnchor = false;
joint.maxDistance = hit.distance * 0.8f;
joint.minDistance = hit.distance * 0.25f;
joint.maxDistance = hit.distance * 0.9f;
if(hit.rigidbody != null){
Rigidbody hitRb = hit.rigidbody;
joint.connectedBody = hitRb;
@ -109,8 +127,8 @@ public class GrappleHook : MonoBehaviour
}else{
joint.connectedAnchor = hit.point;
}
joint.spring = 4.5f * 5f;
joint.damper = 7f;
joint.spring = grappleStrength;
joint.damper = grappleDamper;
joint.massScale = 4.5f;
currGrappleEndPos = transform.position;
@ -119,7 +137,7 @@ public class GrappleHook : MonoBehaviour
private void EndGrapple(){
grappled = false;
lr.enabled = false;
boosted = false;
Destroy(joint);
}
@ -129,4 +147,9 @@ public class GrappleHook : MonoBehaviour
return pointScreenPos;
}
private void ChangeGrappleLength(float value){
if(joint != null)
joint.maxDistance += value;
}
}

View File

@ -171,7 +171,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
@ -2064,7 +2064,11 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
maxGrappleDist: 15
grappleExtendSpeed: 20
grappleExtensionSpeed: 2.5
grappleStrength: 40
grappleDamper: 7
grappleBoostSpeed: 25
grappleDrawingSpeed: 20
grappleableLayer:
serializedVersion: 2
m_Bits: 64
@ -2138,7 +2142,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 50, y: 50}
m_SizeDelta: {x: 52.708637, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1301531514
MonoBehaviour:
@ -2256,7 +2260,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1530935835}
m_LocalRotation: {x: -7.435696e-11, y: 0.9994022, z: -0.03457181, w: -0.000000002149512}
m_LocalRotation: {x: 0.0000000016397671, y: 0.9994022, z: -0.03457181, w: 0.0000000474024}
m_LocalPosition: {x: 4.54, y: 6.64, z: 22.81}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
@ -3187,7 +3191,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2129712287}
m_LocalRotation: {x: -7.435696e-11, y: 0.9994022, z: -0.03457181, w: -0.000000002149512}
m_LocalRotation: {x: 0.0000000016397671, y: 0.9994022, z: -0.03457181, w: 0.0000000474024}
m_LocalPosition: {x: 4.54, y: 6.64, z: 22.81}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -68,7 +68,7 @@ TextureImporter:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
resizeAlgorithm: 1
textureFormat: -1
textureCompression: 1
compressionQuality: 50

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveup : MonoBehaviour
{
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rb.MovePosition(transform.position + new Vector3(0,1,0)*Time.deltaTime);
}
}

View File

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