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