0 votes

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 by (48 points)
edited by

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.

1 Answer

0 votes
Best answer

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 (22,067 points)
selected by

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).

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.