Adjusting the physical material of kinematicbody

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sgsdxzy

I am writing a physical platform game that every character is a rigidbody. I want some bounce between them so I change the physical material of them and set bounce to 1. And I don’t want characters to bounce on ground so I set ground’s bounce to -1. This works as expected.
For moving platforms, I am having some issue that characters slide or drift on horizontally moving ones slightly. I find that the sync_to_physics of kinematicbody perfectly fix this. However, I cannot set the bounce of kinematicsbody and they appear to be always 0, so characters with bounce of 1 would bounce on them. Rigidbody in kinematics mode can have custom bounce, however there’s no sync_to_physics for them and thus the drift issue. Is there a way to fix both?

:bust_in_silhouette: Reply From: mohamedLT

kinematic body does not use physics material so you have to implement the bounce your self or post the code here and maybe we can find the problem and fix it

:bust_in_silhouette: Reply From: sgsdxzy

By looking into the C++ code of RigidBody2D, I found this:

PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce());

This translated to gdscript is

Physics2DServer.body_set_param(get_rid(), Physics2DServer.BODY_PARAM_BOUNCE, bounce)

Tested and it works for all types of PhysicsBody2D. Now I can have a KinematicBody2D that has custom bounce or friction (and many other physics properties that seem to be exclusive to RigidBody).