From c079a6ccbaf9a7653a6368ceb17b191ad857af75 Mon Sep 17 00:00:00 2001 From: Soulaha Balde Date: Wed, 19 Oct 2022 21:35:22 -0400 Subject: [PATCH] Can move up and down on rope Change boosting technique --- .../Grappling}/32bit_jam_conjure.inputactions | 0 .../32bit_jam_conjure.inputactions.meta | 0 Assets/{ => Scenes/Grappling}/GrappleHook.cs | 59 ++++++++++++------ .../Grappling}/GrappleHook.cs.meta | 0 Assets/Scenes/Grappling/Grappling.unity | 14 +++-- .../{ => Scenes/Grappling}/HitMarkerMat.mat | 0 .../Grappling}/HitMarkerMat.mat.meta | 0 Assets/{ => Scenes/Grappling}/anyrgb.com.png | Bin .../Grappling}/anyrgb.com.png.meta | 2 +- Assets/Scenes/Grappling/moveup.cs | 19 ++++++ Assets/Scenes/Grappling/moveup.cs.meta | 11 ++++ 11 files changed, 81 insertions(+), 24 deletions(-) rename Assets/{ => Scenes/Grappling}/32bit_jam_conjure.inputactions (100%) rename Assets/{ => Scenes/Grappling}/32bit_jam_conjure.inputactions.meta (100%) rename Assets/{ => Scenes/Grappling}/GrappleHook.cs (76%) rename Assets/{ => Scenes/Grappling}/GrappleHook.cs.meta (100%) rename Assets/{ => Scenes/Grappling}/HitMarkerMat.mat (100%) rename Assets/{ => Scenes/Grappling}/HitMarkerMat.mat.meta (100%) rename Assets/{ => Scenes/Grappling}/anyrgb.com.png (100%) rename Assets/{ => Scenes/Grappling}/anyrgb.com.png.meta (99%) create mode 100644 Assets/Scenes/Grappling/moveup.cs create mode 100644 Assets/Scenes/Grappling/moveup.cs.meta diff --git a/Assets/32bit_jam_conjure.inputactions b/Assets/Scenes/Grappling/32bit_jam_conjure.inputactions similarity index 100% rename from Assets/32bit_jam_conjure.inputactions rename to Assets/Scenes/Grappling/32bit_jam_conjure.inputactions diff --git a/Assets/32bit_jam_conjure.inputactions.meta b/Assets/Scenes/Grappling/32bit_jam_conjure.inputactions.meta similarity index 100% rename from Assets/32bit_jam_conjure.inputactions.meta rename to Assets/Scenes/Grappling/32bit_jam_conjure.inputactions.meta diff --git a/Assets/GrappleHook.cs b/Assets/Scenes/Grappling/GrappleHook.cs similarity index 76% rename from Assets/GrappleHook.cs rename to Assets/Scenes/Grappling/GrappleHook.cs index de288f7..1bbd7ba 100644 --- a/Assets/GrappleHook.cs +++ b/Assets/Scenes/Grappling/GrappleHook.cs @@ -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(); @@ -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(); 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; + } + } diff --git a/Assets/GrappleHook.cs.meta b/Assets/Scenes/Grappling/GrappleHook.cs.meta similarity index 100% rename from Assets/GrappleHook.cs.meta rename to Assets/Scenes/Grappling/GrappleHook.cs.meta diff --git a/Assets/Scenes/Grappling/Grappling.unity b/Assets/Scenes/Grappling/Grappling.unity index c8e5661..44b69f5 100644 --- a/Assets/Scenes/Grappling/Grappling.unity +++ b/Assets/Scenes/Grappling/Grappling.unity @@ -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 diff --git a/Assets/HitMarkerMat.mat b/Assets/Scenes/Grappling/HitMarkerMat.mat similarity index 100% rename from Assets/HitMarkerMat.mat rename to Assets/Scenes/Grappling/HitMarkerMat.mat diff --git a/Assets/HitMarkerMat.mat.meta b/Assets/Scenes/Grappling/HitMarkerMat.mat.meta similarity index 100% rename from Assets/HitMarkerMat.mat.meta rename to Assets/Scenes/Grappling/HitMarkerMat.mat.meta diff --git a/Assets/anyrgb.com.png b/Assets/Scenes/Grappling/anyrgb.com.png similarity index 100% rename from Assets/anyrgb.com.png rename to Assets/Scenes/Grappling/anyrgb.com.png diff --git a/Assets/anyrgb.com.png.meta b/Assets/Scenes/Grappling/anyrgb.com.png.meta similarity index 99% rename from Assets/anyrgb.com.png.meta rename to Assets/Scenes/Grappling/anyrgb.com.png.meta index ab00e7e..f6ee87d 100644 --- a/Assets/anyrgb.com.png.meta +++ b/Assets/Scenes/Grappling/anyrgb.com.png.meta @@ -68,7 +68,7 @@ TextureImporter: - serializedVersion: 3 buildTarget: DefaultTexturePlatform maxTextureSize: 2048 - resizeAlgorithm: 0 + resizeAlgorithm: 1 textureFormat: -1 textureCompression: 1 compressionQuality: 50 diff --git a/Assets/Scenes/Grappling/moveup.cs b/Assets/Scenes/Grappling/moveup.cs new file mode 100644 index 0000000..ce05773 --- /dev/null +++ b/Assets/Scenes/Grappling/moveup.cs @@ -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(); + } + + // Update is called once per frame + void Update() + { + rb.MovePosition(transform.position + new Vector3(0,1,0)*Time.deltaTime); + } +} diff --git a/Assets/Scenes/Grappling/moveup.cs.meta b/Assets/Scenes/Grappling/moveup.cs.meta new file mode 100644 index 0000000..1573d4f --- /dev/null +++ b/Assets/Scenes/Grappling/moveup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6274607e1747d7342942440e01be026f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: