Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Eatyourvegetables · Apr 20 at 10:14 AM · bugvelocityy-axiscapsulecollider

,Problems with capsule collider 2d and velocity

Ok this is a really weird bug i'm having for some reason my character (only when moving left to right) will randomly go up and down a bit on the y axis i believe it has something to do with the capsule collider as when i use a box collider its fine it will jut get caught on the groud which is why im not doing that it also happens with a cirle collider heres the code (by the way the comments are old lines of original code a wrote ages ago or stuf a commented out trying to find the bug source): using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Player_Movement : MonoBehaviour { public Rigidbody2D rigidbody2D; public float m_speed; //public float gravity = 3f; public float midaircontrol = 1f; public Player_GC gC; public Bannana_Count bac; public Player_Jump pj; public Player_Health ph; public float display; //rigidbody2D.AddForce(new Vector2(0, -gravity), ForceMode2D.Impulse);

 private void Start()
 {
     rigidbody2D = GetComponent<Rigidbody2D>();
     
     
 }

 //rigidbody2D.velocity = Vector2.right * m_speed;
 void Update()
 {        

     //rigidbody2D.AddForce(new Vector2(0, -gravity), ForceMode2D.Impulse);
     if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.D) == false)
         {
         
         /*if (bac.SpeedChange == false)
         {
             m_speed = m_speed + (Time.deltaTime * 15f);
             if (m_speed >= 30f && bac.SpeedChange == false)
             {
                 m_speed = 30f;
             }
         }*/

             if (gC.Grounded == true)
             {
                 //if (pj.jumping == true)
                 //{
                     rigidbody2D.velocity = new Vector2 (-m_speed, rigidbody2D.velocity.y);
             display = rigidbody2D.velocity.y;
             Debug.Log(rigidbody2D.velocity.y + " A key");
             // }
             //else if (pj.jumping == false && ph.damagedoneM == false)
             //{
             // rigidbody2D.velocity = new Vector2(-m_speed, 0);
             // }
         }
             else if(gC.Grounded == false)
             {

                 rigidbody2D.velocity += new Vector2(-m_speed * midaircontrol * Time.deltaTime, 0);
                 rigidbody2D.velocity = new Vector2(Mathf.Clamp(rigidbody2D.velocity.x, -m_speed, +m_speed), rigidbody2D.velocity.y);
             }

         }
     

     else
     {
         if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.A) == false)
         {
             /*if (bac.SpeedChange == false)
             {
                 m_speed = m_speed + (Time.deltaTime * 15f);
                 if (m_speed >= 30f && bac.SpeedChange == false)
                 {
                     m_speed = 30f;
                 }
             }*/
             if (gC.Grounded == true)
             {
                 //if (gC.Grounded == true)
                 //{
                     //if (pj.jumping == true)
                     //{


                         rigidbody2D.velocity = new Vector2 (m_speed, rigidbody2D.velocity.y);
                 Debug.Log(rigidbody2D.velocity.y + " D key");
                 // }
                 //else if (pj.jumping == false && ph.damagedoneM == false)
                 //{
                 //rigidbody2D.velocity = new Vector2(m_speed, 0);
                 //}
                 //}
                 //rigidbody2D.velocity = new Vector2(m_speed, rigidbody2D.velocity.y);
             }
             else if(gC.Grounded == false)
             {
             
             rigidbody2D.velocity += new Vector2(m_speed * midaircontrol * Time.deltaTime, 0f);
             rigidbody2D.velocity = new Vector2(Mathf.Clamp(rigidbody2D.velocity.x, -m_speed, +m_speed), rigidbody2D.velocity.y);
             }
         

         }
         else
         {
             rigidbody2D.velocity = new Vector2(0f, rigidbody2D.velocity.y);

             if (bac.SpeedChange == false)
             {
                 //m_speed = m_speed - (Time.deltaTime * 10);
                 //if (m_speed <= 15f && bac.SpeedChange == false)
                // {
                     m_speed = 15f;
                 //}
             }
         }

         
     }
     




     /*if (Input.GetKeyDown(KeyCode.A) && gC.Grounded == false)
     {
         //rigidbody2D.AddForce(new Vector2(-m_speed, 0), ForceMode2D.Impulse);
         
         rigidbody2D.velocity = new Vector2(-m_speed, rigidbody2D.velocity.y);

     }

     if (Input.GetKeyDown(KeyCode.D) && gC.Grounded == false)
     {
         //rigidbody2D.AddForce(new Vector2(-m_speed, 0), ForceMode2D.Impulse);
         
         rigidbody2D.velocity = new Vector2(m_speed, rigidbody2D.velocity.y);
     }
    */ 
 }

}

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

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

157 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

Related Questions

Rigidbody2D giving incorrect value 1 Answer

Why ForceMode.VelocityChange is inconsistent and how to fix it? 2 Answers

rigidbody2D.velocity.y not recording C# 1 Answer

Check if rigidbody is falling 3 Answers

[bug] Velocity set to 0 by Unity 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