- Home /
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!
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.
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.
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?
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