Bodymovers; what am I doing wrong?

https://gyazo.com/0cecd1f9e34ec5c5c85784774d679089
I have this local script inside of starter character scripts which is meant to control a submarine through body movers. The BodyVelocity is parented to a part within the submarine called root part (the white brick is the root part).
https://gyazo.com/56be33d3c5a4a08fd1d8d1798494987e

The Z velocity in BodyVelocity had changed to 100, however what I don’t understand is why the part wont move?

1 Like

body movers dont replicate to the client

Reading this article I thought players had network ownership over body movers?

Recently network ownership is now only assigned for anchored parts

Even after moving the code to a server script, the model still doesn’t move?
https://gyazo.com/55137d81b44ab113baf38a3c203c2d28

Im confused. Network Ownership can only be assigned on server to Unachored parts, not the opposite. Or am I wrong?
Why changing the network ownership for parts that are not going to move and have physics as achored parts are?

For the code on the server script well make sure the edit the maxforce of the body velocity, not enough force for a heavy submarine with gravity and it’ll of course not move:

MaxForce Determines the limit on how much force that may be applied to each axis

if you want to control it locally give the model to the player using network ownership for each of the base parts through this function:

local function giveModelToPlayer(model, owner)
    local descendants = model:GetDescendants()

    for index, descendant in pairs(descendants) do
        if descendant:IsA("BasePart") then
            descendant:SetNetworkOwner(owner)
        end
    end
end

I’m not sure if you have to set the network ownership of all the parts or just the root part documentation doesn’t seem too clear but yeah for now I’ll just set the network ownership to all the parts.

1 Like

Thanks for the reply, however I only got it moving along the z axis and not the x or y axis?

I think the issue here might be that you’re not giving enough force to the BodyVelocity.
Have you tried increasing the velocity, or ensuring that the MaxForce or Poweron the BodyVelocity is enough to move the entire submarine? (pretend this paragraph is strike-throughed, I don’t know how to do that)

Above paragraph was already answered by the post above, the stuff below is still important though.

If you want to have the submarine always move forwards (which it looks like you’re trying to do with the vector variable), you should do this

SubRootPart.BodyVelocity.Velocity = SubRootPart.CFrame.LookVector * 100

I also wouldn’t recommend having the client have network ownership of the submarine, that’s going to let exploiters teleport anywhere they like.

Whenever W is pressed the model only moves to the right?
https://gyazo.com/f3c6089cd726650138536e717ca35015

Server script

game.ReplicatedStorage.W.OnServerEvent:Connect(function(player, isGoingForward, SubRootPart)
	if isGoingForward then
		print(SubRootPart.CFrame.LookVector)
		SubRootPart.BodyVelocity.MaxForce = Vector3.new(10^10, 10^10, 10^10)
		SubRootPart.BodyVelocity.Velocity = SubRootPart.CFrame.LookVector * 100		
	end	
end)

That means the LookVector for the root part is facing to the right, i.e. the part is rotated 90 degrees. You can either realign the part so the LookVector is facing forwards, or just find which face is facing forwards and use that vector instead (wouldn’t recommend this as its very unintuitive and will make your code unnecessarily confusing)

You can also substitute 10^10 for math.huge (“a value larger than or equal to any other numerical value”), which will make the MaxForce essentially infinite

1 Like

Thanks for the response.
One other question, how could I prevent the model from tilting downwards shown in the video?
https://gyazo.com/626ac4726f381389d75f952c9820f74e

It looks like that’s just gravity doing it’s thing. Found a solution here: How can I make a part unaffected by gravity? - #20 by ThatTimothy

You’re going to want to adjust the original BodyVelocity (which moves the sub) and adjust its MaxForce so that it cannot exert any force on the Y axis

SubRootPart.BodyVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge)

And then create a new BodyVelocity which will keep the submarine’s velocity on the Y axis constantly at 0 (this shouldn’t be touched by the scripts, create this in studio and with these properties)

MaxForce = Vector3.new(0, math.huge, 0)
Velocity = Vector3.new(0, 0, 0)
P = 9000 -- maybe change this, might be too much or too little depending on the submarine's weight

Of course, this solution will only work if the submarines are only ever going to move on a flat, 2D plane. If you want to have non-flat terrain for the subs to move around on, you should instead just add barriers around the world border so they can’t fall off.

2 Likes

You are wrong, it is to client and server for only anchored parts

yes, probably Im totally confuse, sorry. I was just saying that ownership can only be set from server, and for Unanchored parts. Probably we are talking about different topics that I dont understand


1 Like

You don’t assign NetworkOwnership to the BodyMovers themselves, you assign NetworkOwnership to the parts that contain the BodyMovers. If a player has NetworkOwnership of a part, the BodyMovers can be changed on the client and the changes will replicate to the server because the client has ownership over the part.

Rule of thumb, if the client has control over a parts physics then handle the physics on the client in your code.

ONLY UNANCHORED PARTS CAN HAVE THEIR NETWORKOWNERSHIP SET, AND NETWORK OWNERSHIP CAN ONLY BE SET ON THE SERVER!

1 Like