• 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
Question by ndvr_ · Jun 22, 2020 at 03:05 PM · movement3dobjectjumpgameplay

3D Object Jump Glitch

Alright, so after following a few tutorials online about creating an object pickup/ throw script, and implementing a jump mechanic using the character controller, I have t$$anonymous$$s glitch where if the object that the player is holding gets too close to the players ground check (w$$anonymous$$ch regulates jumping based on whether or not the player is on ground - also works on objects if they are classified as the ground layer) you can basically infini-jump so long as your looking down. I just want to note that the pickup script checks the distance between the object and the player, and if it goes too far it drops the item, but it is still able to be moved around wit$$anonymous$$n that range by knocking it into other objects w collision.

I'm looking for a clever fix, but I'll list some potential solutions below that I've thought followed by the reason why they wont work.

Solution 1: Make the player drop the item being held if it gets too close (Doesn't work because my script checks the distance between the exact point on the object you look at before picking it up, so if you look at the farther end of the object, it can get close enough to trigger the glitch still). T$$anonymous$$s is the only solution to work in the slightest, but like I said it depends on w$$anonymous$$ch part of the item you pick up

Solution 2: Make it so that the object is in a fixed position when picking it up, meaning if it collides with another object it wont budge (T$$anonymous$$s one won't work because I'm fairly sure that if I look down at the ground w$$anonymous$$le picking it up, it'll prop my player up, w$$anonymous$$ch is counter intuitive obviously. I could be wrong but I don't want to waste time testing it lol)

Solution 3: Have jumping cool-downs (T$$anonymous$$s just wont work because then it punishes the player for being skillful in their movement. My game will be heavily reliant on precise movements so I'd rather look for another fix.)

Essentially what I have pictured for my game is a valve-esque kind of mini game w$$anonymous$$ch is kind of like a game of tag, more competitive in the sense that it rewards players for $$anonymous$$ding, and penalizes those who are it for not tagging another player. The reason I mention valve is because i really like the flow of movement in games like CS:GO, Half Life, and Portal. Below ill attach some code to better portray what I've mentioned above, hopefully someone will see t$$anonymous$$s and feel free to help. Thanks to those who took the time to even read t$$anonymous$$s :)

Comment

People who like this

0 Show 2
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 ndvr_ · Jun 22, 2020 at 04:46 AM 0
Share

My pickup and throw script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PickUpAndThrow : MonoBehaviour {

 float throwForce = 18000;
 Vector3 objectPos;
 float distance;

 public bool canHold = true;
 public GameObject item;
 public GameObject tempParent;
 public bool isHolding = false;

 // Update is called once per frame
 void Update()
 {

     distance = Vector3.Distance(item.transform.position, tempParent.transform.position);
     if (distance >= 5f || distance <= 1.5f)
     {
         isHolding = false;
     }
     //Check if isholding
     if (isHolding == true)
     {
         item.GetComponent<Rigidbody>().velocity = Vector3.zero;
         item.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
         item.transform.SetParent(tempParent.transform);

         if (Input.GetMouseButtonDown(1))
         {
             item.GetComponent<Rigidbody>().AddForce(tempParent.transform.forward * throwForce);
             isHolding = false;
         }
     }
     else
     {
         objectPos = item.transform.position;
         item.transform.SetParent(null);
         item.GetComponent<Rigidbody>().useGravity = true;
         item.transform.position = objectPos;
     }


     /////////////////////////////////////////////////////////////
     /*

     if (Input.GetMouseButtonDown(0))
     {
         if (distance <= 5f && distance >= 2f)
         {
             isHolding = true;
             item.GetComponent<Rigidbody>().useGravity = false;
             item.GetComponent<Rigidbody>().detectCollisions = true;
         }
     }

     if (Input.GetMouseButtonDown(0) && isHolding)
     {
         isHolding = false;
     } 

     */


 }

 void OnMouseDown()
 {
     if (distance <= 5f && distance >=1.5f)
     {
         isHolding = true;
         item.GetComponent<Rigidbody>().useGravity = false;
         item.GetComponent<Rigidbody>().detectCollisions = true;
     }
 }
 void OnMouseUp()
 {
     isHolding = false;
 }
 

}

avatar image ndvr_ · Jun 22, 2020 at 04:46 AM 0
Share

Movement Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Movement : MonoBehaviour { public CharacterController controller; public Transform playerHeight; //does nothing lol

 public float speed = 16f;
 public float gravity = -50f;
 public float jumpHeight = 10f;


 bool isCrouching;
 public Transform groundCheck;
 public float groundDistance = 0.7f;
 public LayerMask groundMask;

 Vector3 velocity;
 bool isGrounded;

 // Update is called once per frame
 void Update()
 {
     

     //Crouching mechanic
     if (Input.GetKey(KeyCode.LeftControl))
     {
         isCrouching = true;
         controller.height = 1.80f; //makes player ~60% of initial height
     }
     else
     {
         isCrouching = false;
         controller.height = 3.18f;//makes player reg height again
         speed = 16f;
     }
     //Checks if ur touching the ground while crouching, to slow you down.
     if (isGrounded && isCrouching)
     {
         speed = 8f; //slows player down to half movement speed if crouching
     }

     //Sprint Mechanic
     if (Input.GetKey(KeyCode.LeftShift) && isCrouching == false && isGrounded)
     {
         speed = 24f; //speeds player up to 1.5x movement speed if running
     }
     


     isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); //declares isGrounded bool

     if(isGrounded && velocity.y < 0)
     {
         velocity.y = -10f; //regulates velocity if ur standing on ground
     }

     float x = Input.GetAxis("Horizontal"); //determines x axis placement
     float z = Input.GetAxis("Vertical");   //determines z axis placement

     Vector3 move = transform.right * x + transform.forward * z; //gives player movement

     controller.Move(move * speed * Time.deltaTime); //allows the player to move at a consistent speed (does not exceed framerate)

     if (Input.GetButton("Jump") && isGrounded)
     {
         velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity); //jump equation
     }
    
     velocity.y += gravity * Time.deltaTime; //y velocity decreases over time if not grounded

     controller.Move(velocity * Time.deltaTime); //regulates speed w framerate


 }

}

0 Replies

· Add your reply
  • Sort: 

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

234 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 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

how to rotate one piece and make another move linearly? 0 Answers

In Air Movement 0 Answers

Making a character jump with the Character Controller Component instead of Capsule Collider 0 Answers

Move while jump on board 0 Answers

Smaller object jumps around bigger when dragged by mouse cursor 0 Answers


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