Topic was automatically imported from the old Question2Answer platform.
Asked By
Brazda
What is a situation:
Having object1 as main character with KinematicBody2D .
Having circle shape collider on object1.
Before calling method move_and_collide(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 move_and_collide
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?
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.
Allright.
Two separate questions:
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?
Brazda | 2019-06-14 14:22
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?