How to make model straight when falling?

I have a tool that when clicked spawns a crate in front of the character. It is working all fine and dandy apart from the fact that it can tilt/rotate and it makes it look buggy when it falls. Because of this, I was wondering if it was possible to keep the model upright without and rotation while it is falling.

Here is the server script that spawns the crate:


local spawnevent = game.ReplicatedStorage.Tools.PlaceCrate

function spawncrate(player,objectname,placepos)
	local crate = game.ServerStorage:FindFirstChild(objectname)
	if crate ~= nil then
		local clone = crate:Clone()
		clone.Parent = game.Workspace.SpawnedProps
		clone:SetPrimaryPartCFrame(placepos + Vector3.new(0,1,0))
		local EntireModel = clone:GetChildren()
		
		wait(1)

		for i,v in pairs(EntireModel) do
			if v:IsA("BasePart") then
				v.Anchored = true
			end
		end
	end
end

spawnevent.OnServerEvent:Connect(spawncrate)

Also, here is a video of what I mean by buggy falling

1 Like

Try doing CFrame:ToWorldSpace(), this will give you the option to set a CFrame whilist respecting the direction and rotation of a part.

I think its the physics of the falling.

why do you wait 1 second before anchoring?

So it anchors after its hit the ground

Alright i understand but you can also use raycast in this scenario.

You can try putting the box 2 studs in front of the player, shoot a raycast downwards and get the position once it hits the ground. Teleport the box to that position but add the height of the box divided by 2.

It sounds complicated but its not really. This is ofcourse not the only way of doing it but it should work

NOTE: if this does not work or is too complicated you can always use BodyGyro so the rotation of the box does not change

I’ve searched up about bodygyros but I’ve never understood them. Maybe I’ve just watched bad tutorials.

Okay so its actually pretty simple

image

The maxTorque is a vector3. In this case the bodygyro adds force to the X and Z axis and removes force from the Y axis. So if i add this body gyro to any part it will lock the Y rotation only cause the Y rotation does not have any force.

You can change the strength of the body gyro with D and P but you just have to play around with those to see which one fits the best

I hope this makes you understand body gyro’s a bit more. I am not that good of a teacher so just let me know if its still not clear haha :smiley:

Could I insert it into the whole model or would I need to put it in every part?

every part but you can give the model a primary part and weld all parts to that primary part and add the bodygyro inside of it

Alright, thanks. I’ll try that and get back to you.

Okay that worked perfectly. Thank you.

1 Like