Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Finn10232137 · Jul 11, 2017 at 01:10 PM · unity 2d

cant jump well on moving platform

hello guys my character cant jump well on moving platform. when i press Space on other ground, my character will jump smooth, the GetButton works very well and Sensitive, but here is the problem, when i stand on moving platform , my Space always cant work very well, i tried to debug it , i cant fix it , pls help me , thx lot.

here is my character C#

     public GameObject Dog;
     private float my_runspeed = 8; 
     private float my_jumpHeight = 800; 
     private Animator my_ani; 
     private bool Jumping = false;  
     private bool IsGround = false; 
 
     void Awake () {
         my_body = GetComponent<Rigidbody2D> ();  
         my_ani = GetComponent<Animator>();  
     }
 
 
     void FixedUpdate () {
                 MyJump();
                 MyMove ();
         My_StateMachine ();
         my_JumpState ();
     }
 
 
     void MyMove () {
         float myxy = Input.GetAxis ("Horizontal");  
         my_body.velocity = new Vector2 (myxy * my_runspeed, my_body.velocity.y);  
 
         if (myxy != 0) {  
             float my_Scale_X = Mathf.Sign (my_body.velocity.x) == 1 ? 1 : -1; 
             Dog.transform.localScale = new Vector3 (my_Scale_X, 1, 1);
         }
     }
 
 
     void MyJump () {
         if (!IsGround != false || my_body.velocity.y != 0) {return;}  
 
         if (Input.GetButton("Jump")) {
             Debug.Log(my_body.velocity); 
             my_body.AddForce (Vector3.up * my_jumpHeight);  //Vector3.up = (0,1,0)
         }        
     }
 
 
     void My_StateMachine () {
         my_ani.SetFloat ("Speed", Mathf.Abs (my_body.velocity.x));  
         my_ani.SetBool("Jumping", Jumping); 
         my_ani.SetBool("IsGround", IsGround);  
     }
 
 
     void my_JumpState () {
         if (my_body.velocity.y > 0.1f) { 
             Jumping = true;
             IsGround = false;
         }else if(Jumping){
             Jumping = false;
         }
     }
 
 
     void OnCollisionEnter2D(Collision2D coll)
     {
         if (coll.gameObject.tag == "Ground" && coll.contacts[0].normal == Vector2.up) {
             IsGround = true;
         }



here is setParent

    private Transform Target;  
     public GameObject Character;  
     public GameObject Platform;  
     void OnCollisionEnter2D(Collision2D coll)  { 
         if(coll.gameObject.tag == "Player" && coll.contacts[0].normal == -Vector2.up) 
         {                                                                             
             Target = coll.gameObject.transform; 
             Target.SetParent(Platform.gameObject.transform);  
         }
     }
 
     void OnCollisionExit2D(Collision2D coll)  { 
         if(coll.gameObject.tag == "Player")  
         {
             Target = coll.gameObject.transform;  
             Target.SetParent(Character.gameObject.transform);  
         }
     }
 
 }


here is moving platform

     public GameObject Platform;  
     public float min;  
     public float max; 
     private float Position_now; 
     private bool Move = true;  
     public float speed = 1f;  
 
     void Update() {
 
         Position_now = Platform.gameObject.transform.localPosition.x; 
         if (Move == true) { 
             Platform.transform.localPosition += new Vector3(speed, 0, 0); 
             if (Position_now >= max) {  
                 Move = false;
             }
         }
    
         if (Move == false) {
             Platform.transform.localPosition += new Vector3(-speed, 0, 0); 
             if (Position_now <= min) { 
                 Move = true;
             }
         }
     }
 
 }
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

109 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

Related Questions

2 touch Destroy(gameObject); 2 Answers

how to approach connecting different boss parts(gameobjects) to one health bar that calculate damage when a part gets destroyed? 0 Answers

Making an App Prototype without Coding 0 Answers

anyone here to help me with adobe animate 0 Answers

spawn position of ragdolls keep doubling 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