Тёмный

How To Code Ledge Grabbing for your Unity Game 

The Game Dev Cave
Подписаться 22 тыс.
Просмотров 8 тыс.
50% 1

Опубликовано:

 

29 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 21   
@tommycorsetti8152
@tommycorsetti8152 2 месяца назад
I've adapted this for a first person movement script. I'm going to try and work some lerp functions into this somehow. I wouldn’t have had a clue where to start if it wasn't for this vid. thank you
@fear-the-phantom
@fear-the-phantom 7 месяцев назад
Good vid, gonna try it out for my Banjo-Kazooie style prototype
@rxmfdddddddd
@rxmfdddddddd 5 месяцев назад
Found you!
@fear-the-phantom
@fear-the-phantom 5 месяцев назад
@@rxmfdddddddd ?
@rxmfdddddddd
@rxmfdddddddd 5 месяцев назад
@@fear-the-phantom I follow you on twitter :D
@elpela6975
@elpela6975 6 месяцев назад
Hello, my problem is that sometimes it grabs a higher side and other times a lower side of the box.
@KawaiiProductions
@KawaiiProductions 6 месяцев назад
Does this work for the Third Person template as well?
@apoorvpandey3D
@apoorvpandey3D Год назад
I use godot and this was very helpful to me. Thank you!
@LaughingMajora
@LaughingMajora 10 месяцев назад
Hello! :D i have a problem, can you help me, please? my character doesnt keep hanging the edge :C im using a raycast jump this is my jump code do you need my entire code? private void PlayerJump() { if (Input.GetButtonDown("Jump") && isGrounded) { if(hanging) { _rb.useGravity = true; hanging = false; _rb.AddForce(Vector3.up * Jump, ForceMode.Impulse); StartCoroutine(EnableCantMove(0.25f)); } else { _rb.AddForce(Vector3.up * Jump, ForceMode.Impulse); } } }
@thegamedevcave
@thegamedevcave 10 месяцев назад
Seems like you’re setting gravity to true when your character is hanging, it should be set to false and then back to true when the hanging stops
@LaughingMajora
@LaughingMajora 10 месяцев назад
@@thegamedevcave im kinda lost :'C can you help me, please? this is my full code public class RbController : MonoBehaviour { [SerializeField] private Rigidbody _rb; [SerializeField] private Camera _camera; [SerializeField] private float _rotation; [SerializeField] float Jump = 5f; public float movementSpeed; public float raycastDistance = 0.2f; public float swingDamping = 0.95f; public bool isJump = false; public bool isGrounded = false; public bool hanging; bool canMove = true; public Transform currentAnchor; private bool isAtach; private SpringJoint _springJoint; public LayerMask groundLayer; // Start is called before the first frame update void Start() { _rb = GetComponent(); } // Update is called once per frame void Update() { PlayerMovement(); PlayerJump(); Anclar(); LedgeGrab(); RaycastHit hit; if (Physics.Raycast(transform.position, Vector3.down, out hit, raycastDistance, groundLayer)) { isGrounded = true; } else { isGrounded = false; } if (isAtach) { ApplySwingDamping(); } } private void PlayerMovement() { if (canMove) { float Hor = Input.GetAxis("Horizontal"); float Ver = Input.GetAxis("Vertical"); Vector3 velocity = Vector3.zero; Vector3 direction = Quaternion.Euler(0, _camera.transform.eulerAngles.y, 0) * new Vector3(Hor, 0, Ver); Vector3 movementDirection = direction.normalized; if (Hor != 0 || Ver != 0) { velocity = direction * movementSpeed; if (movementDirection != Vector3.zero) { Quaternion desiredRotation = Quaternion.LookRotation(movementDirection, Vector3.up); transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, _rotation * Time.deltaTime); } } velocity.y = _rb.velocity.y; _rb.velocity = velocity; } } IEnumerator EnableCanMove(float waitTime) { yield return new WaitForSeconds(waitTime); canMove = true; } private void PlayerJump() { if (Input.GetButtonDown("Jump") && isGrounded) { if(hanging) { _rb.useGravity = true; hanging = false; _rb.AddForce(Vector3.up * Jump, ForceMode.Impulse); StartCoroutine(EnableCanMove(0.25f)); } else { _rb.AddForce(Vector3.up * Jump, ForceMode.Impulse); } } } void Anclar() { if (Input.GetButtonDown("Sujetarse") && currentAnchor != null) { isAtach = true; _rb.useGravity = false; _springJoint = gameObject.AddComponent(); _springJoint.connectedBody = currentAnchor.GetComponent(); _springJoint.autoConfigureConnectedAnchor = false; _springJoint.connectedAnchor = new Vector3(0f, -7f, 0f); _springJoint.spring = 40.5f; _springJoint.damper = 10f; _springJoint.massScale = 2f; } else if (Input.GetButtonDown("Sujetarse") && isAtach) { isAtach = false; //_rb.useGravity = true; Destroy(_springJoint); } } void ApplySwingDamping() { _rb.velocity *= swingDamping; } void LedgeGrab() { if (_rb.velocity.y < 0 && !hanging) { RaycastHit downhit; Vector3 lineDownStart = (transform.position + Vector3.up * 1.5f) + transform.forward; Vector3 lineDownEnd = (transform.position + Vector3.up * 0.7f) + transform.forward; Physics.Linecast(lineDownStart,lineDownEnd,out downhit, LayerMask.GetMask("Ground")); Debug.DrawLine(lineDownStart,lineDownEnd); if(downhit.collider != null) { RaycastHit forwardHit; Vector3 lineForwardStart = new Vector3 (transform.position.x, downhit.point.y-0.1f,transform.position.z); Vector3 lineForwardEnd = new Vector3 (transform.position.x, downhit.point.y-0.1f, transform.position.z) + transform.forward; Physics.Linecast(lineForwardStart, lineForwardEnd, out forwardHit, LayerMask.GetMask("Ground")); Debug.DrawLine(lineForwardStart, lineForwardEnd); if (forwardHit.collider != null) { _rb.useGravity = false; _rb.velocity = Vector3.zero; hanging = true; Vector3 hangPos = new Vector3(forwardHit.point.x, downhit.point.y, forwardHit.point.z); Vector3 offset = transform.forward * -0.1f + transform.up * -1f; hangPos += offset; transform.position = hangPos; transform.forward = -forwardHit.normal; canMove = false; } } } } }
@RacTeamGames
@RacTeamGames Год назад
how can you add thr vector3s and i cant
@thegamedevcave
@thegamedevcave Год назад
you're likely typing vector3 instead of Vector3.
@RacTeamGames
@RacTeamGames Год назад
@@thegamedevcave Im not its just not working
@thegamedevcave
@thegamedevcave Год назад
@@RacTeamGames if you're having trouble with the basics like adding a variable I suggest you first take a step back and go through some of my unity basics videos ru-vid.com/group/PLoReGgpfex3xS-zXTujxo_flRkLBgxxd3
@TheDigitalLenny
@TheDigitalLenny Год назад
Hello I been having some issues with my fwdRayCast and tried using a debug to see why my player wasn't finding the ledge. It seems to only register the Down hit raycast are there any solutions to this problem? //Foward Cast if (downHit.collider != null) { Debug.Log("DOWN HIT"); lineFwdStart = new Vector3(transform.position.x + downHit.point.y - 0.1f, transform.position.z); lineFwdEnd = new Vector3(transform.position.x + downHit.point.y - 0.1f, transform.position.z) + transform.forward; Physics.Linecast(lineFwdStart, lineFwdEnd, out forwardHit, hangMask); Debug.DrawLine(lineFwdStart, lineFwdEnd, Color.red); if (forwardHit.collider != null) { Debug.Log("FWD HIT"); rb.useGravity = false; rb.velocity = Vector3.zero; isHanging = true; //Hang animation Vector3 hangingPos = new Vector3(forwardHit.point.x, downHit.point.y, forwardHit.point.z); Vector3 offset = transform.forward * -0.1f + transform.up * -1f; hangingPos += offset; transform.position = hangingPos; transform.forward = -forwardHit.normal; } }
@thegamedevcave
@thegamedevcave Год назад
i'm thinking it might be this line lineFwdEnd = new Vector3(transform.position.x + downHit.point.y - 0.1f, transform.position.z) + transform.forward; you're adding transform.forward to it, which is correct but now your line cast is only casting a really short distance in front of the character, just 1 single unit. you want to probably muliply that transform.forward by some number (i'd suggest making it a variable to test out what number works best)
@TheDigitalLenny
@TheDigitalLenny Год назад
@@thegamedevcave Thank you the player is starting to react! to the hanging but is off and sometimes will be hanging about the wall haha. I also saw i had an error in my code i had: lineFwdEnd = new Vector3(transform.position.x + downHit.point.y - 0.1f, transform.position.z) + transform.forward; istead of: lineFwdEnd = new Vector3(transform.position.x, downHit.point.y - 0.1f, transform.position.z) + transform.forward; 🤦‍♂😂
@elpela6975
@elpela6975 6 месяцев назад
@@TheDigitalLenny try do this in the last part of de function: if (fwdHit.collider != null) { Invoke(nameof(NewPosHang), 0.01f); } } } } public void NewPosHang() { rb.useGravity = false; rb.velocity = Vector3.zero; hanging = true; Vector3 hangPos = new Vector3(fwdHit.point.x, downHit.point.y, fwdHit.point.z); Vector3 offset = transform.forward * -0.1f + transform.up * -1f; hangPos += offset; transform.position = hangPos; transform.forward = -fwdHit.normal; }
@GENNAROTHEBEST94
@GENNAROTHEBEST94 8 месяцев назад
is this can be use in the 2d context?
@thegamedevcave
@thegamedevcave 8 месяцев назад
Should be yeah, might need a 2d specific verion of line cast for it though, not sure
Далее
How to Make a FORCE FIELD Shader in Unity
9:30
Просмотров 6 тыс.
Climbing System In Unity | Zelda Tutorial
4:24
Просмотров 31 тыс.
skibidi toilet 77 (part 4)
05:20
Просмотров 16 млн
Voy shetga man aralashay | Million jamoasi
00:56
Просмотров 412 тыс.
Modular Combo System for Combat in Unity
20:29
Просмотров 36 тыс.
How to make a Video Game - Godot Beginner Tutorial
1:17:12
Why Stairs Suck in Games... and why they don't have to
11:24
#37 Ledge Grabbing (Part1) - Unity Tutorial
27:10
Просмотров 25 тыс.
THIRD PERSON MOVEMENT in Unity
21:05
Просмотров 1,5 млн
How I Remade Only Up in 24hrs! | Unity
6:57
Просмотров 3,2 тыс.
How to code SMARTER A.I. enemies | Unity Tutorial
32:49
Third Person Ledge Climbing with Unity & Playmaker
18:25
Unity Tutorial: RigidBody Step Up Stairs
12:27
Просмотров 61 тыс.