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 gw707 · Sep 27, 2021 at 01:51 PM · playerplayer movementmoving platforminfinite runner

Issue with player landing on moving platform - Infinite Runner

I’m making an infinite runner game and have it set so that the platforms move to the left rather than the player moving forwards. My issue is that I have a platform the loops up and down as it moves left and when my player lands on this specific platform, they start bouncing off the platform, which isn’t what I want. Bouncing GIF

One way to solve this is by having the player as a child of the platform, which does work and stops the bouncing, but it also means that the player is then moving left along with the platform. Child GIF

I know why this is happening as a child object will follow the parent object, but I can’t find a way to have my player act to not move with the platform without the bouncing issue.

The player has a rigidbody and box collider attached, the moving player only has a box collider.

Player jumping script:

 if (Input.GetMouseButtonDown(0))
     {
         player_RB.velocity = new Vector2(player_RB.velocity.x, 20);
     }

Moving platform script:

 private int moveVertical;
 
 void Start()
 {
     moveVertical = Random.Range(1, 3);
 }
 
 void Update()
 {
     transform.position -= transform.right * (Time.deltaTime * 7);
 
     if (transform.position.x <= -20)
     {
         Destroy(gameObject);
     }
 
     if (transform.position.y < -2f)
     {
         moveVertical = 1;
     }
     else if (transform.position.y > 2f)
     {
         moveVertical = 2;
     }
 
     if (moveVertical == 1)
     {
         transform.position = new Vector2(transform.position.x, transform.position.y + 5 * Time.deltaTime);
     }
     else if (moveVertical == 2)
     {
         transform.position = new Vector2(transform.position.x, transform.position.y - 5 * Time.deltaTime);
     }
 }

Can anyone offer a solution to this? I just want the player to land on the moving platform normally without bouncing or moving to the left with the platform.

123.gif (402.1 kB)
456.gif (365.8 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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by finjonathan · Sep 27, 2021 at 02:26 PM

Try setting the player velocity to right and equals to the speed the platforms are moving when he becomes a child of them and set it to normal speed (0 i think) when it is no longer a child

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 ricky_lee_ · Sep 27, 2021 at 03:21 PM

finjonathan's answer would be what I'd try doing aswel.

Though I can't help thinking a parent/child system could become messy, Did you ever try using FixedUpdate() instead of Update() on your moving platform?

Or possibly try adding a physics material on your 2D Rigidbody?


Make a 2D Physics material in your assets. Select it and make sure it's bounciness value is 0 in the Inspector. alt text


Then Select your Player in the hierarchy, and drag the 2D Physics material you just made into the material property of the Player's 2D RigidBody Component.

alt text


next.png (81.6 kB)
first.png (64.5 kB)
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 gw707 · Sep 27, 2021 at 05:12 PM

@finjonathan

I've tried setting the velocity to right but it hasn't worked unfortunately. I'm not moving my player, I've just got the platforms moving to the left so setting the players velocity to right results in inconsistant movement.

I tried setting the player velocity to a new vector2 and this kind of worked but the player starts jittering when landing on the platform.

@ricky_lee_

I should have mentioned that i've already created a physics material and set the bounciness to 0, but no luck. Also, using FixedUpdate for the platform movement made no difference either.

Comment
Add comment · Show 1 · 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 finjonathan · Sep 27, 2021 at 06:32 PM 0
Share

Another idea is to not set that as a Child but instead if is Grounded set the vertical speed equal to the platform speed. Have you also set the material to the player and the platforms too?

avatar image
0

Answer by SatansPineapple · Sep 27, 2021 at 09:37 PM

take an emptygameobject and attach the platform and another emptygameobject as child attach a collider to the empty child;

move the empty game object(parent) and set the player as child to the child with collider.

dont set the player to the platform directly as child.

Comment
Add comment · Show 1 · 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 gw707 · Sep 29, 2021 at 02:49 PM 0
Share

Appreciate the suggestion but this hasn't work either i'm afraid. I still get the same issue as i get when setting the player as a child to the platform directly as mentioned in the initial post.

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

166 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

Related Questions

NavMeshAgent Not Working? 1 Answer

Player is Speeding up in collisions 0 Answers

Player boundaries based on screen resolution 1 Answer

i want to move a rigidbody using touch button 0 Answers

Cannot Rotate Player after Matching Camera Rotation? 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