0 votes

What is a situation:
Having object1 as main character with KinematicBody2D .
Having circle shape collider on object1.

Before calling method moveandcollide(velocity) in object1's script:
Suppose we have velocity: Vector2(10, 0) --- here we are going to the left.
And suppose another object2 is coming from the top. What to do how to detect that object2?

Notes:

  • object2 is also KinematicBody2D
    i have choosen KinematicBody2D for object2, because i don't need the physics to be applied to the object2, and that's why i have moved him by code and not by physics.

  • i choose for main character KinematicBody2D in place RigidBody2D, because i don't need the physics to be applied to the object1.

  • i want the collision to be detected by object1's script, in his moveandcollide

Second question:
Did i choose wisely types of my objects?
Third question:
Should main character be RigidBody2D in order to detect collisions from all sides?

in Engine by (65 points)

1 Answer

0 votes

Kinematic bodies only detect collision when they move. They do not detect bodies hitting them.

If another body moves into it, that body must process the collision.

In object2's script, notify the collider (object1) that it was hit.

by (22,067 points)

Allright.
Two separate questions:
1. What if i have n objects just like object2, should all of them carry collision logic? Are they going to slow whole game?

.2. Should i change my object1 and object2 to something else if for object1 and object2 is ok not to be effected by pychics?

1) Yes. If all of them are moving, they already have movement logic. Add a line that says something like:

if collision:
    collision.collider.react()

Where react() is whatever function on object1 you want it to execute when it's hit. It's the same amount of code, it's just being called by the moving object, not the stationary one.

Why would you expect this to cause a performance issue?

2) There are pros and cons to each body type. Which is the right choice for you depends on many factors. See here for some suggestions: https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html

  1. I have expected that it is better that you have colliding logic on one object rather on n objects.
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.