Hai, my simple project has 2 rigid body 1 as player and 1 as obstacle, the obstacle moving using addcentralforce(Vector3(0,0,750)), im not sure that is the best way im just try anything , but it works,i want to make it stop when the player hit obstacle using addcentralforce(Vector3(0,0,0)) but i think it dont stop the obstacle
how can i solve this?

in Engine
edited

It seems it all already works for you. So just a comment.

If you want the obstacle to be "steady as a rock" then you can use a staticbody (or a rigidbody in static mode). (and move it just by changing its position)

But if you want the obstacle to react to the collision then using a RigidBody is just correct.

A call to `add_central_force()` just acts for the time span of one physics frame. Probably, you call it again on every `_physics_process`?. The collision will automatically create a counterforce to the related rigid bodies. Naturally, the mass of the rigidbodies will influence acceleration and collisions.

`add_central_force()` means just that: add a force to the body. To remove a force, you'd need to add its opposite: `add_central_force(Vector3(0, 0, -750))`. This will cancel out the first force.

Note, this will not stop the body, just stop it accelerating - see Newton's 1st law of motion.

Can I ask why you're using RigidBody? It's often the case that dealing with physics just makes things more complicated than they need to be. KinematicBody may be a better choice.

by (21,718 points)
selected

ive an educational project and the tutorial for my project using unity using rigidbody, the project is trying to make it like the tutorial show us or better and im trying using godot,

is static body can move?

and i think rigidbody has a natural effect when something hit another thing,

i try to export it in android and its work, the player stop and work like i want, but thanks for your suggestion

Just so that there are no misunderstandings here:
`add_central_force()` only requires an opposite force to be cancelled out when this is needed in the very same physics frame.

In Godot, applied forces only live for one physics frame (and have to be renewed each frame if you want the force to be applied constantly).