# How to make Rigid body 2D stick to static body 2D and slide across?

Attention Topic was automatically imported from the old Question2Answer platform.

I’ve read the articles about rigid body 2d and static body 2d, but they don’t seem to go into extensive detail. If there’s something–or somethings–that I should be reading, please let me know as I’m eager to learn more.

I’m making a side scrolling skateboard game similar to T&C for NES. I suppose it has some kind of non-standard properties since the character can move up and down within the field. Thus far I have gravity turned off, a force propelling my character forward, and my animated sprite has rolling wheels.

This works good for just rolling along and doing tricks. But I also need to be able to make my character interact with the terrain, and grind/slide on ledges and rails. I’ve got my animations all figured, and a seemingly-achievable means for creating the controls. But I don’t understand how to get my character to interact with my objects the way I’d like.

What I’m hoping to achieve is basically some kind of “magnetic” function where a signal will trigger an animation change, my character will stick to a ledge (static body 2d), be propelled across it with noticeably decreased friction, continue off of the ledge, and emit a signal to trigger the landing animation.

I’m guessing I’ll need to use collision shape, and area 2d to define the static body 2d. But should I make the static body have a force that propels the character, or should the static body have drastically decreased friction? And what can I do to make the rigid body character stick to the static body ledge?

Thanks.

I recommend you use a `KinematicBody` instead. It gives more control and is more predictable.

Here is a tutorial in 2D.

SIsilicon | 2018-12-13 21:02

OK, thanks for the tip, but how does using a kinematic body solve my problem? I still need my kinematic body to stick to my static body objects without using global gravity. Totally realistic physics won’t work.

It’s isometric movement within a 2 dimensional plane if that makes sense? There’s no ground as far the game physics are concerned–the character is always floating in space–but through a combination of the animations, and limitations on the physics engine, it creates an accurate depiction of riding a skateboard along a sidewalk.

Would it be possible to make my static body objects have independent gravity? Basically using area 2d to assign a gravity field directly above the static body object, and then it would pull my character down onto the object? And then give it a directional velocity so that it propels the character along the object?

The image below should give a good reference for the way my level is set up. I need my character to be able to move up and down in the field while a force propels the character towards the right edge of the screen, and let the user navigate a path through a course of obstacles. I hope that’s more clear.

ZachMoldof | 2018-12-14 18:19

Totally realistic physics won’t work.

That is exactly why you don’t want to use a `RigidBody`. It’s all about realistic physics. Now with a `KinematicBody` you can implement any kind of movement you want that doesn’t have to obey the laws of physics.

Would it be possible to make my static body objects have independent gravity?

That wouldn’t be necessary when using a `KinematicBody`. What you’d do instead is detect when you collide with it, then use a different block of code for moving it along the rail. When done colliding with it, you’d then go back to using code for moving it along the road.

The image below should give a good reference for the way my level is set up.

I can’t see the image. :-/

SIsilicon | 2018-12-14 19:06

Ahh ok, very helpful thank you.

as far as the image I’m not sure what the deal is? I pasted the url into the prompt that popped up when i hit the ‘insert image’ button. It’s here though.

ZachMoldof | 2018-12-14 19:19

I think I have a pretty solid understanding of the kinematic body 2d now. Thanks for the pointer. I definitely see how move and slide is exactly what I need. And I understand the concept of setting a “floor normal”. However, I’m not clear on how I apply the floor normal property to my static body objects?

ZachMoldof | 2018-12-15 15:54

You don’t. The floor normal just helps Godot to know what collisions should be considered as a floor one. If for example you set the floor normal to `(0,-1)`, then any collision with a normal close to that will be considered a floor.

SIsilicon | 2018-12-15 16:37

I recommend you use a `KinematicBody` instead. It gives more control and is more predictable.