• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Razputin · Apr 14, 2021 at 02:40 PM · jumpjumpingminecraftautomatic

Minecraft Style Auto Jumping

Does anyone know how the "Auto Jumping" is achieved in Minecraft?

For those who don't know "Auto Jump" will allow the player to climb blocks without having to press the space bar.

I was thinking a system like that could be good for walking up stairs, but unsure.

Let me know your thoughts, thanks!=

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HellsHand · Apr 14, 2021 at 03:43 PM

You could use a raycast, when it hits an object you dub as climbable, the character jumps. As far as how it's done in Minecraft, I haven't coded since Java edition was only available.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Razputin · Apr 14, 2021 at 03:59 PM 0
Share

Ah if that's all it's doing that doesn't sound ideal.

avatar image HellsHand Razputin · Apr 14, 2021 at 04:04 PM 0
Share

I guess another less taxing way than a constant raycast could be to add a collider a little bigger than the object to jump up that acts as a trigger and when the player enters the trigger, they jump.

avatar image
1

Answer by Nistroy · Apr 15, 2021 at 03:59 PM

I tried since yesterday ways to make the automatic jump and tell me if it suits you @Razputin

 using UnityEngine;
 using UnityEngine.Events;
 
 public class AutoJumpScript : MonoBehaviour
 {
     RaycastHit[] hits;
     // Capture all the GameObjects you have to jump
 
     float distance;
     // The distance at which it detects a GameObject.
 
     [SerializeField] float maxDistance = 20f;
     // The value not to be exceeded for the maximum distance at which it detects a GameObject.
 
     [SerializeField] float minDistance = -10f;
     // The value not to be exceeded for the minimum distance at which it detects a GameObject.
 
     [SerializeField] LayerMask groundMask;
     // The LayerMask that detects.
 
     //[SerializeField] --- (if you want to reference it from the inspector, then remove the double slashes)
     PlayerMovement movement;
     // Your player's movement script reference.
 
     [SerializeField] UnityEvent jumpScript;
     // The jump event to Invoke.
 
     void Start()
     {
         movement = GetComponentInParent<PlayerMovement>();
     }
 
     // Update is called once per frame
     void Update()
     {
         distance = Mathf.Clamp(GetMax(Mathf.Abs(movement.hozizontalmovement), Mathf.Abs(movement.verticalmovement)), minDistance, maxDistance);
         // The "distance" value clamped between the maximum and minimum value
         // Horizontal movement and vertical movement are the values ​​when the player is moving (Input.GetAxis ("Horizontal") for example)
 
         hits = Physics.RaycastAll(transform.position, new Vector3(movement.hozizontalmovement, 0, movement.verticalmovement), distance, groundMask);
         // Get all the GameObjects detected with the LayerMask defined in "groundMask" with the distance at which it can detect a game object and the direction the raycast goes.
 
         foreach (RaycastHit hit in hits)
         {
             Debug.Log(hit.transform.name);
             jumpScript.Invoke(); // Invoke the jump function
             break; // Stop the loop to avoid calling it more than once, although normally you can jump again only if you hit the ground.
         }
     }
 
 
     public static float GetMax(float first, float second)
     {
         return first > second ? first : second;
     }
 
     private void OnDrawGizmos()
     {
         Gizmos.color = Color.red;
         Gizmos.DrawRay(transform.position, new Vector3(movement.hozizontalmovement, 0, movement.verticalmovement));
     }
 }
 

Edit: you need to place the GameObject with this component in the parent Player object. Adjust the Y axis position to jump according to the desired height.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

118 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Others can't jump in my game 0 Answers

Anti-Gravity isn't working 1 Answer

Adding a jump feature help? 2 Answers

3D Game-Making a character jump 3 Answers

How would I get my character to be able to move while in the air after a jump? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges