Having a problem with BodyForce

I’m trying to have some parts that I spawn in move in the direction that a different part is facing. Currently I’m using a BodyForce to counter gravity for the parts and I can make them move in a given direction, but I want to be able to rotate the main part without having to worry about changing values in the script again. Here’s the relevant code (sorry, I don’t know how to put it in code format):

local bf = Instance.new(“BodyForce”,part)
bf.Force = Vector3.new(0, part:GetMass()*game.Workspace.Gravity, 0)

I tried applying an additional BodyVelocity aimed at the lookVector of the part, but the parts that will be spawned in are different sizes and I was unable to figure out how to make them move at equal speeds. Is there a way I can make the BodyForce move the spawned in parts in the direction the main part is facing?

BodyForce cannot apply a force relative to the object. Even though you can always convert a vector from object to world space, this too will only work for the initial vector from object space. Instead, you should use a BodyThrust object, as also mentioned on the BodyForce page:

To apply a force at a specific point (e.g. to apply torque for angular acceleration) or apply forces relative to the orientation of the part, use a BodyThrust instead.

While using the BodyThrust object, you need only give the LookVector once and then BodyThrust will keep exerting force with respect to the current LookVector.

local thrust = Instance.new(“BodyForce”)
thrust.Force = part.LookVector * workspace.Gravity
thrust.Parent = part

P.S.

  • Don’t use Instance.new() for parenting, see why here
  • You can use codeblocks in the following format:
    ```lua
    – Code
    ```
1 Like

Sorry, I don’t think I described my situation in very clear terms. What I wanted to do is essentially fire projectiles in the direction of the lookVector of the part I use to set the CFrame of the projectiles, not the lookVector of the projectile itself. The code you provided just caused the parts to fall straight down. Fortunately, I was able to get the results I wanted by simply adding a second BodyForce (Somehow I considered using a second BodyMover in the form of a BodyVelocity but not another BodyForce), one to account for gravity and the other to move the projectiles in the direction they need to go in at equal speeds. Here’s what I ended up doing:

	local bf = Instance.new("BodyForce")
	bf.Force = positionpart.CFrame.lookVector * part:GetMass() * 1.5
	bf.Parent = part
	local force = Instance.new("BodyForce")
	force.Force = Vector3.new(0,part:GetMass()*game.Workspace.Gravity,0)
	force.Parent = part

Thank you for your help :happy1:

Perhaps unnecessary addition but you could just set:

part.Velocity = positionpart.CFrame.lookVector * {part:GetMass() * 1.5} -- you can safely replace the curly brackets with some random constant like 22, however fast you want the part to move

But this will instantly accelerate the part (as in go from not moving to moving at full speed instantly)
Your method will accelerate the part based on the BodyForce’s Force value
Also remember to mark the question as solved

you can use body angular velocity, as it rotates the part with a desired force

It sounds like you want to use a RocketPropulsion.

You can set the RocketPropulsion target to the part you are “aiming” at, and it will move and turn automatically towards the part forever.

RocketPropulsion.Target = TargetPart
RocketPropulsion:Fire() -- Nessesary to start the effect

Here is a GIF from the wiki post.

image

As you can see, the RocketPropulsion object forces the part to “chase” the other one. For more information, refer to this: RocketPropulsion

I’d be happy to answer any questions you might have.