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 /
avatar image
0
Question by ferodrigueza1998 · Mar 23, 2020 at 04:20 PM · movementendless runner

Make a character not be affected by floor movement

Hi, I'm having a bit of a problem with an Endless Runner 2D game I have just started developing. I did a bit of research online and found out that the optimal way to create an endless runner is to make the players x position fixed, and create the illusion of movement by scrolling the background and the floor.

I am trying to do that, and I have achieved to endlessly move my background and floor and reposition while not in camera. However, my character is going to be running on the floor. Whenever he collides with the floor, the ground's rigidbody is making my character move at the same speed the floor is moving, with no way to fix it and eventually moving offscreen to the left.

So my problem is that I need my player to collide with the ground, but no ground forces should be applied to my character so he can stay "running in place". And I can't freeze my character's x position because I will try to implement a dash later, for which I need x-axis movement.

This is my first question so apologies if I have done something wrong. Thank you and stay safe, everyone!

Comment
Add comment · Show 1
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 CobbledGames · Mar 23, 2020 at 04:29 PM 0
Share

Essentially this is to do with physics. I suggest using a physics2D material and apply it to the player so you can change the affect of physics on them. I bet someone else could give a better answer though.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by schwollie · Mar 25, 2020 at 03:15 PM

Hi, an easy workaround for this problem might be to just set the friction in the physics material of the ground to zero. But it might be better to just freeze the x-position and instead move your camera and the world accordingly. A dash move could also be implemented by moving just your camera and the world.

Comment
Add comment · Show 2 · 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 ferodrigueza1998 · Mar 25, 2020 at 06:41 PM 0
Share

Hi, I thought about moving the camera and the world to implement a dash but that doesn't give the effect I wanted. I am messing with things around so I might try that, though.

However, I think I fixed it by removing the floor's rigidbody, and just moving the transform.position I am not sure how much of a great practice or efficient it is, but it is working right now. If it turns out to be a bad solution I'll come back to it later.

 float newPosition = $$anonymous$$athf.Repeat(Time.time * GameControl.instance.backgroundScrollSpeed, scrollOffset);

Does the code seem wrong to you?

avatar image CobbledGames ferodrigueza1998 · Mar 25, 2020 at 09:18 PM 0
Share

That seems alright apart from Time.time, use Time.deltaTime ins$$anonymous$$d as Time.time is tied to the current Frames per second. deltaTime is not. Ohh and don't forget to test after making a change.

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

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

Player is falling to the sides 2 Answers

Player gets stuck while moving in 3d endless runner 0 Answers

Multi-lane endless runner. How to toggle lanes? 1 Answer

Why doesn't my collision detection script work when using OnTriggerEnter, however when using OnCollisionEnter it doesn't work at all... Would really like to know.. Thank you in advance 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 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