Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollisionObject2D Guide #13

Open
cbscribe opened this issue Sep 5, 2017 · 2 comments
Open

CollisionObject2D Guide #13

cbscribe opened this issue Sep 5, 2017 · 2 comments

Comments

@cbscribe
Copy link
Member

cbscribe commented Sep 5, 2017

I've also volunteered to write a guide to the various CollisionBody2D objects - what they're for, what they're not for, etc.

Suggestions welcome for tips, details, examples - anything that might be helpful. One goal is to discourage the inappropriate use of RigidBodies (something I've seen frequently by beginners).

@Warlaan
Copy link

Warlaan commented Sep 6, 2017

When I explain the four node types I draw a two-by-two-matrix on the board:

moved by physics engine moved by code
Physics during movement RigidBody KinematicBody
No physics during movement StaticBody Area

There's two nodes for objects that are moving in the physics world (RigidBody and KinematicBody) and two for objects that don't move or where the movement isn't affected by physics (StaticBody and Area).
And then there's two nodes for objects that are "owned" by the physics engine and that you may manipulate (PhysicsBody and StaticBody) and two nodes that are "owned" by you and that can be used to ask the physics engine for information (KinematicBody and Area).

So for example in a game of pong I would use a RigidBody for the ball, because its movement is physically "correct", so there's no reason for me to rewrite it when the RigidBody has all it needs to perform linear movement and reflect the ball from the paddles.
For the paddles however I would use StaticBodies, because they themselves should not be affected by physics (they shouldn't be pushed back by the ball).
So "Static" doesn't mean that a StaticBody can't move, it just means that it won't be moved by the physics engine.
Nevertheless it's the better choice than using Areas or KinematicBodies, because sticking to RigidBodies and StaticBodies allows the physics engine to handle the speed of the ball.

On the other hand if I was moving a player around traps I would be using KinematicBody for the player and Area for the traps, because the player will move according to joystick or keyboard input and I want to be able to ask whether movement is possible or not, and because the location of the traps' trigger areas is not affected by the physics engine, but it may be affected by script code, for example when a trap is animated (like a view cone from an enemy).

@cbscribe
Copy link
Member Author

cbscribe commented Sep 6, 2017

  moved by physics engine moved by code
Physics during movement RigidBody KinematicBody
No physics during movement StaticBody Area

I love this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants