How prevent rigidbody push another rigidbody?

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

Exist 2 rigidbody (A and B) and static ground
A - move to B (via direct linear_velocity), collide and push B.
Need stop A to prevent push B. B can push A, but A - not.
Friction, mass, kinematic mode and another hack - not need.

:bust_in_silhouette: Reply From: Magso

The simple answer would be to make B a kinematic body but it depends on what other behaviour you’re wanting from them. Alternatively you could use the body_entered signal and move A the same direction and speed as B as long as B is moving towards A.

answered and find solution

SuperDIMMaX | 2019-12-22 02:57

:bust_in_silhouette: Reply From: dahiya.bunty1

rigid body use phyics… so try mass or use area body signal… then multiple A by _1

Friction, mass, kinematic mode and another hack - not need.

Problem with first impact A to B - B recive impulse. I manual set Linear velocity for B to compensate move B (based on substract A Linear velocity), but problem B recive Angular velocity, i try compencate this, but… bugs… B still alitle rotate.
Another variant… don`t know how to direct acceess to PhisycalServer to prevent create new impulse/force.
If try exclude A from B in collision settings (on this moment) - A can not recive impilse from B

SuperDIMMaX | 2019-12-22 18:59

:bust_in_silhouette: Reply From: SuperDIMMaX

No. kinematic not affected physics. (forces, impulse, gravity, friction, joints, damp… etc…) Need full Rigidbody… for A and B
I created move_and_slide function for Rigidbody.

Apply_Linear = if Input.is_action_pressed("ui_up"): Apply_Linear += Vector3(0,0,-1)

func _integrate_forces(state):
	If Apply_Linear == Vector3.ZERO:
		return
	state.linear_velocity.x = Apply_Linear.x  
	state.linear_velocity.z = Apply_Linear.z
		
	var space: PhysicsDirectSpaceState = get_world().direct_space_state as PhysicsDirectSpaceState
	var param = PhysicsShapeQueryParameters.new()
	param.shape_rid = PhysicsServer.body_get_shape(get_rid(),0)
	param.transform = transform
	param.collision_mask = 2     # All Rigidbody like as B - in Layer 2
	var magick_cast = space.cast_motion(param, state.linear_velocity*state.get_step() )
	
	if magick_cast[0] != 0 or magick_cast[0] != 1:
		param.transform.origin += state.linear_velocity*state.get_step()* magick_cast[1]
		var collision = space.get_rest_info(param)
		if collision.has("collider_id"):
			linear_velocity = Vector3.ZERO # Move and stop

If need slide effect - collision has “normal”

state.linear_velocity.x = (state.linear_velocity.slide(collision["normal"])).x 

i keep debug slide effect… it not work perfect :confused:
and need rewrite code - move “magick_cast” in function