is_colliding for just touching, no force?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

Is it possible to check for when a kinematic body is touching an element without a force applied?

For example, when using is_colliding(), your body must be moving in that direction to be true. Is is there a function to check if it’s just touching another body? I’m new to physics so forgive me. I’m checking the docs now :smiley:

:bust_in_silhouette: Reply From: Zylann

In 2D, you can do this to perform arbitrary space queries with the space state, here is an example:

var space_state = get_world_2d().get_direct_space_state()
var circle_shape = CircleShape2D.new()
circle_shape.set_radius(_body_radius)
var query = Physics2DShapeQueryParameters.new()
query.set_shape(circle_shape)
query.set_transform(Matrix32(0, next_pos))
query.set_exclude([self])
query.set_layer_mask(GROUND_MASK)
var hits = space_state.intersect_shape(query, 32)

Feel free to check the doc about all classes and functions involved here. I never tried in 3D but it should be similar.
It can only be done inside a _fixed_process() callback, as the physics engine is in sync with the game logic.

You don’t need every parameter, I just happen to have this in my game so I pasted it here :slight_smile:

Edit: if this code is called a lot in your game (every frame?), you should consider reusing objects to minimize the impact of memory allocation (SomeClass.new objects, arrays…)