How to Make Simple Ladders in Unity | 5 Minute Unity Tutorials

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 66

  • @octobeard4946
    @octobeard4946  3 года назад +33

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityStandardAssets.Characters.FirstPerson;
    public class ladderScript1 : MonoBehaviour
    {
    public Transform chController;
    bool inside = false;
    public float speedUpDown = 3.2f;
    public FirstPersonController FPSInput;
    void Start()
    {
    FPSInput = GetComponent();
    inside = false;
    }
    void OnTriggerEnter(Collider col)
    {
    if(col.gameObject.tag == "Ladder")
    {
    FPSInput.enabled = false;
    inside = !inside;
    }
    }
    void OnTriggerExit(Collider col)
    {
    if(col.gameObject.tag == "Ladder")
    {
    FPSInput.enabled = true;
    inside = !inside;
    }
    }
    void Update()
    {
    if(inside == true && Input.GetKey("w"))
    {
    chController.transform.position += Vector3.up / speedUpDown;
    }
    if(inside == true && Input.GetKey("s"))
    {
    chController.transform.position += Vector3.down / speedUpDown;
    }
    }
    }

  • @itJPepper
    @itJPepper 3 года назад +5

    Was searching for ages to find a simple and working ladder code for my uni project, this was incredibly helpful. Thank you!

    • @octobeard4946
      @octobeard4946  3 года назад +2

      No worries man. I was in the same boat. Searching for ages. Couldn’t find one. So I made one. Glad it helped. 👍👍

  • @SkyLeon-iu3ee
    @SkyLeon-iu3ee 3 года назад +13

    Here is same code with slight modification
    I had to use Time .deltaTime to reduce speed of movement of my character while inside of box,which doesn't have to be bad...Without it,Box can be used as cannon,you only apply gravity after exiting of box...
    Here is part of code i modified:
    void Update()
    {
    if (inside == true && Input.GetKey(KeyCode.W))
    {
    charCTRL.transform.position += Vector3.up * speedUpDown * Time.deltaTime;
    }
    if (inside == true && Input.GetKey(KeyCode.S))
    {
    charCTRL.transform.position += Vector3.down * speedUpDown * Time.deltaTime;
    }
    }

  • @ahmetomercicek5848
    @ahmetomercicek5848 Год назад +1

    I did everything and it worked but the ground terrain is attached and when I don't press the w key on the ladder, it starts to fall down, how can I solve this problem, thank you.

  • @marianl8092
    @marianl8092 2 года назад

    pretty cool! gonna turn a modification of this to a simple obstacle climbing, too.

  • @RoseliaChan-sk7xv
    @RoseliaChan-sk7xv 2 месяца назад

    y u check if w is pressed instead of checking for vertical input?

  • @Visuwyg
    @Visuwyg 3 года назад +1

    what a pleasant tutorial! these are rare, I'll try to follow this tomorrow, but using Bolt.

  • @malitver
    @malitver 10 месяцев назад

    I need an animation to trigger when climbing stairs, how do I do that?

  • @lawrence4301
    @lawrence4301 2 года назад +1

    your channel avatar is sick haha, nice

  • @gmangman123
    @gmangman123 Год назад

    I can't stay on the ladder If I release the W key, the player slides down?

  • @2013BoysLigaTeam
    @2013BoysLigaTeam 3 года назад +1

    The script sorta works, the player will enter the trigger and climb up but never exits when it gets to the top, instead just starts to head down. Also player gets stuck/freeze if it lands on top of the trigger. Not sure if you could maybe point me in the right direction? I'm using photon for the player controller

    • @octobeard4946
      @octobeard4946  3 года назад

      I’ve never used Photon before, but there have been some issues with its colliders. This page here might help: forum.unity.com/threads/photon-players-go-through-each-other.822654/

    • @benjamintinkhauser4500
      @benjamintinkhauser4500 3 года назад

      @@octobeard4946 ive also got that problem. any ways to fix this now?

    • @octobeard4946
      @octobeard4946  3 года назад

      @@benjamintinkhauser4500 Is this for a multiplayer game? There is something on this here: www.google.co.uk/amp/s/amp.reddit.com/r/Unity3D/comments/3x1eus/character_controller_with_photon_networking/

    • @octobeard4946
      @octobeard4946  3 года назад

      @@benjamintinkhauser4500 other than that, I’m afraid I don’t know. I’ve never used Photon.

    • @benjamintinkhauser4500
      @benjamintinkhauser4500 3 года назад

      @@octobeard4946 Yes its for a photon multiplayer game. The ladders work but i cant get out of the hitbox if im on top. And on ground i cant move if im next to the ladder

  • @drnovetti9392
    @drnovetti9392 2 года назад +1

    does this also work with ThirdPerson starter assets?

    • @octobeard4946
      @octobeard4946  2 года назад +1

      Should do. But there won’t be any climbing animations… unless you set them up.

    • @drnovetti9392
      @drnovetti9392 2 года назад +1

      @@octobeard4946 love it! thanks for the tutorial

    • @octobeard4946
      @octobeard4946  2 года назад +1

      Np 😊

  • @zarkaun96
    @zarkaun96 Год назад

    Excellent video. So I'm running into an issue where when I go up the ladder, and then back down, the character goes down the inside of the ladder (the side that is against the wall). Any idea on how to fix this?

    • @Nemko77
      @Nemko77 7 месяцев назад

      After a year maybe you solved it already, but if not, just simply change the size of the collider. I have the collider infront of the ladder, so when the player obj. interacts with it, it's not going to be "inside" the ladder or wall.

  • @HausCoding
    @HausCoding 3 года назад +3

    very helpful thankss!!

  • @vincenzosparks2516
    @vincenzosparks2516 3 года назад +1

    This tutorial was amazing and so are you, Sir! :) Looks like I'm getting stuck at the top (not using Photon) as well. But, I should be able to figure it out.

  • @KronosPGR
    @KronosPGR 3 года назад +1

    It works thanks! Btw how to enable the rotation of the camera while going up?

    • @octobeard4946
      @octobeard4946  3 года назад

      Hi. Thanks for getting in contact. This script does not support that feature as it disables the whole FPS Input for the duration of the climb. You’d need to look at just disabling the movement controls (but not the look controls), but this could get quite messy as the look controls determine which way is forward (and so which way is sideways and - most importantly - up...).

    • @KronosPGR
      @KronosPGR 3 года назад +1

      @@octobeard4946 i just copypaste muy rotation lines into the update of your script and works fine! Easy and useful thanks

    • @octobeard4946
      @octobeard4946  3 года назад

      @@KronosPGR That’s great. Happy to know it works with you controller. 👍👍

  • @somenians
    @somenians 3 года назад +1

    when i enter the ladder collider and press w, my character flings upwards, and when I press s, my character falls under the map. I made sure that the collider is slightly offset upwards from the bottom of the ladder, so I'm not really sure what I did wrong. any help is appreciated ty.
    edit: nvm i fixed it, but in case someone else encounters this problem, try setting the ladder mvmt speed a little higher. i set mines to around 30 which resulted in a steady climb speed

    • @AHWilliams614
      @AHWilliams614 Месяц назад

      three years later, thank you for this!

  • @AbyssalSoda
    @AbyssalSoda 3 года назад +1

    The type or namespace name 'FirstPersonController' could not be found (are you missing a using directive or an assembly reference?)

    • @lazikbro12
      @lazikbro12 2 года назад

      mee to bc i have not installed standard assets from unity store

  • @Shubham-bk2cf
    @Shubham-bk2cf 3 года назад

    How to make player look at ladder only while climbing?

  • @MaximilianoDavidDucoli
    @MaximilianoDavidDucoli 3 года назад +1

    Hi. man! Great tutorial!
    Do you know how can i made a ladder, but in 2.5D
    Just like ghost'n goblins have.
    I can´t made it yet.
    Sorry my poor english, but i speak spanish.
    Tank you!

    • @RetroRedDog
      @RetroRedDog 2 года назад

      Did you solve this? I am wanting to do the same

    • @MaximilianoDavidDucoli
      @MaximilianoDavidDucoli 2 года назад +1

      @@RetroRedDog
      I still couldn't finish doing it properly, but since I'm just in the prototype of my game, for now they are just tests and later when I have everything well thought out, I will make the corresponding arrangements.
      If you improve it before me, please, I ask you if you pass me the corrections.
      In the player controller there are some interactions too, that's why I attached it to the package.
      drive.google.com/drive/folders/12tD1lSm678nlLouCrl-cfcBpoYkQdQvY?usp=sharing
      Thanks a lot!

    • @RetroRedDog
      @RetroRedDog 2 года назад

      @@MaximilianoDavidDucoli Thank you, yes sure if I can improve it I will send it over to you

  • @KamuCreates
    @KamuCreates 3 года назад +1

    this is great! I'm just learning Unity and trying to keep things simple. I managed to tweak this for a crude 3rd person view but I am wondering if its Possible to get this to work with collision, I have platforms i need my character to have to move around but they just go right through.

    • @octobeard4946
      @octobeard4946  3 года назад

      Have you tried adding a second collider? Or a sub-model with its own collider on it...?

    • @KamuCreates
      @KamuCreates 3 года назад

      @@octobeard4946 i figured it out! I tried using stoppers like i saw in another video where they set it to move you in the opposite direction, but if the collision wasn't totally on it would move you in the wrong direction and the only fix on that was 4 offset colliders which was way too much stuff. A friend suggested using the y velocity instead of transform to move the character controller and that solved the issue!

    • @SkyLeon-iu3ee
      @SkyLeon-iu3ee 3 года назад +3

      void Update()
      {
      if (inside == true && Input.GetKey(KeyCode.W))
      {
      charCTRL.transform.position += Vector3.up * speedUpDown * Time.deltaTime;
      }
      if (inside == true && Input.GetKey(KeyCode.S))
      {
      charCTRL.transform.position += Vector3.down * speedUpDown * Time.deltaTime;
      }
      }
      this helped me, try it out.

  • @ROSTUDIO224
    @ROSTUDIO224 11 месяцев назад

    Привет а если у меня свои код движение и персонаж как изменить

  • @vladimirsantos2318
    @vladimirsantos2318 3 года назад

    How am i gonna make the ai use ladder?

  • @lazikbro12
    @lazikbro12 2 года назад +1

    nope my character cant exit the ladder

  • @twistypunch
    @twistypunch Год назад

    I can't even run the game with this script in the project. Does this not work with VRChat?

  • @隨風幻影
    @隨風幻影 3 года назад

    I tried to run the script but my character went under the map and kept dropping, what can I do?

  • @ilonpilaaja
    @ilonpilaaja 2 года назад

    Very Cool

  • @pekaala7319
    @pekaala7319 3 года назад +1

    thank you bro

    • @octobeard4946
      @octobeard4946  3 года назад +1

      No worries, dude. I noticed that there weren’t any decent tutorials for this so I thought I’d make one. It’s simple. But it does the job. 👍👍

  • @teamfury7484
    @teamfury7484 2 года назад

    When i enter the ladder my character start flying and when it lands i cant use my control

  • @Visuwyg
    @Visuwyg 3 года назад +1

    I translated your tutorial into Bolt Visual Scripting and it worked first try! Unfortunately, your solution is rather limited, the camera is locked and getting off the ladder is very finnicky. Going down a ladder is near impossible. Thanks for the quick win but I'll need a "proper" solution...

  • @benjamintinkhauser4500
    @benjamintinkhauser4500 3 года назад

    my character is just flying upwards when i start the game

    • @octobeard4946
      @octobeard4946  3 года назад

      Did you put the script on the player or on the ladder?

    • @benjamintinkhauser4500
      @benjamintinkhauser4500 3 года назад

      @@octobeard4946 On the player but i just fixed it. It was because of the character controllet

    • @octobeard4946
      @octobeard4946  3 года назад +1

      @@benjamintinkhauser4500 that’s great news. What was the fix (in case anyone else asks)??

    • @benjamintinkhauser4500
      @benjamintinkhauser4500 3 года назад +2

      @@octobeard4946 just remove the character controller component from the player, if youre using photon player controller

    • @octobeard4946
      @octobeard4946  3 года назад +2

      Thanks for letting me know. I’ll be sure to tell others having this problem. 👍👍

  • @iamthedislikebutton7899
    @iamthedislikebutton7899 3 года назад +2

    I'm here just incase

  • @hehehe8626
    @hehehe8626 3 года назад

    For me dont work pls help

    • @hehehe8626
      @hehehe8626 3 года назад +1

      i use 2018.4.35f1 and FPScontroller from unity standart assets