• 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 gizelgeng · Aug 15, 2020 at 06:00 AM · jumprotatingperpendicularsticking

how to jump Perpendicular to the rotating platform

Hello , first of all i wanted to apologize for my bad English. i have a simple jumping game . in this game there are rotating platforms , and a game object , whenever the player clicks mouse the game object should jump and stick to the next platform and rotate with it ,until the player clicks again. i want the game object to jump Perpendicular to the rotating platform` (again sorry for my bad English) but now in my code it dose not. and if i use Vector3.up the game object will fall down ,i've tried every thing but it dose not work

alt text

i want the game object to jump in the direction of green arrow and stick to the next platform

alt text

, here is my code

     Rigidbody2D Rig;
     public float Force =500;
     public bool gamejump = true;
     public Transform platformParent;   
     bool playerforce = false;
     bool setpos = false;
     Vector2 pos = new Vector2(0, 0);
     public Collider2D Ccollider;
     public bool bottom =false;
     public bool SPressed = false;
     void Start()
     {
         Rig = GetComponent<Rigidbody2D>();
         Ccollider = GetComponent<CircleCollider2D>();
     }
     void Update()
     {
         if (SPressed == true && Input.GetKeyDown(KeyCode.Space))
         {
             print("true");
             gamejump = true;
             Rig.AddForce(transform.up * Force);
         }    
 
         if (gamejump == true)
         {
             transform.SetParent(null);
             Rig.isKinematic = false;
             setpos = false;
         }
         else
         {
             transform.SetParent(platformParent);
             Rig.AddForce(new Vector2(0, 0));
             Rig.isKinematic = true;
             if (setpos == false)
             {
                 setpos = true;
                 transform.position = pos;
             }
 
             /*    if(Input.GetMouseButtonDown(0))
               {
                   SPressed = true;
               }
                 if(Input.GetMouseButtonUp(0))
               {
                   SPressed = false;
               }
            }*/
         }
     }
     void OnTriggerStay2D(Collider2D other)
     {
         if (other.tag == "Rotate")
         {
             SPressed = true;
             // if(SPressed==true)
             //if (Input.GetKey(KeyCode.Space) )  
             // if (Input.GetMouseButtonDown(0))
             //  {
             // gamejump = true;
             /* if (bottom == true)
              {
                  Rig.AddForce(other.transform.up * Force);               
              }
              else
              {
                  Rig.AddForce(other.transform.up * -Force);
 
              }
              }
         */
             //  }  
         }
     }
 
     void OnCollisionEnter2D(Collision2D collision)
     {
         if (collision.gameObject.tag == "Rotate")
         {
             ContactPoint2D contact = collision.contacts[0];
             pos = contact.point;
             if (collision.contacts.Length>0)
             {
                 bottom = true;
             }
             else
             {
                 bottom = false;
             }
             gamejump = false;  
         }
     }
     public void OnCollisionExit2D(Collision2D collision)
     {
         collision.collider.enabled = false;
     }
 }
 

i have to press key space 3 times to jump and i don't know why! so that is my main problem for now.

whatsapp-image-2020-08-15-at-102027-1.jpeg (15.2 kB)
whatsapp-image-2020-08-15-at-102027.jpeg (22.4 kB)
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

132 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

Related Questions

Object rotates from Y velocity on Collision 2 Answers

How to make sure that my cube can only jump when in contact with the ground 2 Answers

Path constrained characters. 1 Answer

2D (With Planes) Jump Script 0 Answers

2D Charge Jump Complications 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges