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 Aggrojag · Jun 24, 2014 at 11:33 AM · c#2djumpdetectionground

Ground Detection Lagging - 2D

So, I've been trying to find a means of fixing this issue, and I'm finally resorting to this here for some of you more knowledgeable folks.. So, basically I'm working on a 2D game. I've tried several different means of ground detection and the only thing I can find that works is a bit conflicting. I've tried physics2D.CircleOverlap, raycasting, line casting, and even setting up a trigger to tell the PlayerController script when it touches the ground. However, if the player reaches a certain speed, they will sink someway in the ground before stopping. This generally happens once jumping off a platform to a lower surface...

To fix this problem, I've turned "Is Kinematic" off of my player object. However, I'm simulating my own gravity through scripting, and would like to ignore physics for this, and most other objects. Simply putting the Gravity scale to 0 isn't exactly my ideal means of resolving this issue. Any advice at all is much appreciated, also, my jumpScript is much longer than this, but this shows all the movement stuff related to it. If you do need any more information at all, please feel free to ask, I figured a shorter version would be more efficient for whoever is reading ^_^.

Edit: I wrote this up when I was rather tired. I noticed a couple errors in my script, so just updating that.

 using UnityEngine;
 using System.Collections;
 
 public class TestScript : MonoBehaviour {
 
     private float decreaseTimer;
     public float decrease;
     public GameObject bottom;
     private bool jumping;
     private Vector3 bottomVec;
     public float jumpHeight;
 
     
     // Update is called once per frame
     void FixedUpdate () {
         if(Input.GetKey (KeyCode.Space)){
             jumping = true;
             //IfInputJumpisTrue
         }
         if(IsGrounded() == false){
             decreaseTimer += Time.deltaTime;
             //TimeLengthOfJump-MultipleSubtractionByThis
         }
 
         if(IsGrounded()){
             decreaseTimer = 0f;
             jumping = false;
             //ResetTimer
 
         }
 
         if(jumping){
             transform.Translate(0f, jumpHeight - (decrease * decreaseTimer), 0f);
             //WillEventuallyReturnNegative
         }
 
 
     }
 
 
     private bool IsGrounded(){
         bottomVec = bottom.transform.position;
         return Physics2D.Linecast(transform.position, new Vector3(bottomVec.x ,bottomVec.y), 1 << LayerMask.NameToLayer("Ground"));
         //LineCast,CheckForGround
     }
 }
 
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

Answer by Aggrojag · Jun 28, 2014 at 06:40 AM

So, after digging through Unity, I believe I found the answer to my question. When Is Kinematic is set to false, unity will check to see if the object is inside of another object. If it is, it will offset the value of the transform until it is outside of the object. I would provide sample script to get around this if I knew how, so my apologies that this is not provided! Cheers!

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
avatar image
0

Answer by grendayzer77 · Feb 08, 2016 at 11:31 AM

i had the same problem and i've set Collision Detection to Continuous instead of Discrete, and it solved the problem.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D C# Jump Script Addforce 2 Answers

Distribute terrain in zones 3 Answers

Help With Simple Jump Script 1 Answer

GetButtonDown not always firing 1 Answer

2d Raycast problem from enemy to player C# 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