Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 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 this glitch where if the object that the player is holding gets too close to the players ground check (which 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 within 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). This is the only solution to work in the slightest, but like I said it depends on which 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 (This one won't work because I'm fairly sure that if I look down at the ground while picking it up, it'll prop my player up, which 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 (This 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 which is kind of like a game of tag, more competitive in the sense that it rewards players for hiding, 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 this and feel free to help. Thanks to those who took the time to even read this :)

Comment
Add comment · 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

$$anonymous$$y pickup and throw script:

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

public class PickUpAndThrow : $$anonymous$$onoBehaviour {

 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.Get$$anonymous$$ouseButtonDown(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.Get$$anonymous$$ouseButtonDown(0))
     {
         if (distance <= 5f && distance >= 2f)
         {
             isHolding = true;
             item.GetComponent<Rigidbody>().useGravity = false;
             item.GetComponent<Rigidbody>().detectCollisions = true;
         }
     }

     if (Input.Get$$anonymous$$ouseButtonDown(0) && isHolding)
     {
         isHolding = false;
     } 

     */


 }

 void On$$anonymous$$ouseDown()
 {
     if (distance <= 5f && distance >=1.5f)
     {
         isHolding = true;
         item.GetComponent<Rigidbody>().useGravity = false;
         item.GetComponent<Rigidbody>().detectCollisions = true;
     }
 }
 void On$$anonymous$$ouseUp()
 {
     isHolding = false;
 }
 

}

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

$$anonymous$$ovement Script:

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

public class $$anonymous$$ovement : $$anonymous$$onoBehaviour { 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 Layer$$anonymous$$ask ground$$anonymous$$ask;

 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 $$anonymous$$echanic
     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, ground$$anonymous$$ask); //declares isGrounded bool

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

     float x = Input.GetAxis("Horizontal"); //deter$$anonymous$$es x axis placement
     float z = Input.GetAxis("Vertical");   //deter$$anonymous$$es z axis placement

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

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

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

     controller.$$anonymous$$ove(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.

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

In Air Movement 0 Answers

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

Move while jump on board 0 Answers

Moving player in direciton camera is facing 1 Answer

ai jump over object 2 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