Hey!
In connection with a new small project, it would be necessary to create a mining cart that I can push. I decided that the appropriate way to do this is to have the cart welded to the player when the player grabs it.
The problem is that before welding the cart to the player, the location and orientation of the cart model would need to be set based on the location and orientation of the player.
For example, that the cart is 1 stud ahead of the player and the orientation is parallel to the player.
I haven’t really worked with CFrame before, and I lack a lot of knowledge about it. A search for a similar problem does not return any answers.
At the moment, I have a script that moves the model, but not in front of the player, but to a completely random place on the map, not to mention its orientation.
So the help I’m asking for is: How to set the position and orientation of this model with the player’s HumanoidRootPart (A little ahead of the player)
I’ve been trying for a long time now and I’m starting to lose hope lol.
Thanks!
(PrimaryPart: CartArea)
local Cart = script.Parent.Parent.Parent
local CartArea = script.Parent.Parent.Parent.CartArea
script.Parent.Triggered:Connect(function(plr)
if not CartArea:FindFirstChild("ConnectionWeld") then
local CharacterCFrame = plr.Character.HumanoidRootPart.CFrame
Cart:PivotTo(CFrame.new(CharacterCFrame*CharacterCFrame.LookVector*2))
--CreateWeld
local WeldC = Instance.new("WeldConstraint")
WeldC.Name = "ConnectionWeld"
WeldC.Parent = CartArea
WeldC.Part0 = CartArea
WeldC.Part1 = plr.Character.HumanoidRootPart
end
end)
Workspace:
Visual desired result: