Yes, “result” is generated from a raycast straight down. its hitting the baseplate. the part hovers a stud above the ground. the parts pivot point is dead center in the part - I haven’t moved it.
I’m sorry, FartFella, but I’m not sure what your response meant.
However, we are also making this work for objects that slant in space, so a deployable can be placed on a slant. As such, the 1/2 height won’t totally work, I don’t think?
I just thought of a way to do the slant. If you performed your vertical raycast, then cast another ray that’s basically the same as the first one but oriented to the rotation of the part that the first raycast hit. So basically you cast a vertical ray and it hits the baseplate, then it performs another one based on the surface of the baseplate the first raycast hit to determine the slant of the said placed object. Maybe I’m rambling on about something pointless because I haven’t tested this so sorry if this is wrong. I also might be saying something pointless if raycasts automatically do this.
thanks ! let us know if you get it working. we are still researching, but the API is incomplete, no one on youtube seems to be teaching this (as obvious as it is) and the tutorials often don’t work or aren’t clear!
My apologies for misunderstanding, I very well have tried all of the code I had provided in my previous post and it worked fine. So how exactly is the problem occurring when you use CFrame:ToWorldSpace()? With the code used, what is currently happening to the object?
the full code I’m using (also edited to first post above.)
local tool = script.Parent
local storage = game.ReplicatedStorage
local u = require(game.Workspace.Utility)
local playerService = game:GetService("Players")
tool.Activated:Connect(function()
local char: Model = script.Parent.Parent
local player = playerService:GetPlayerFromCharacter(char)
--untoggle local teamTag = char:FindFirstChild("TeamTag")
--local char = script.Parent.Parent
local deployment = storage:WaitForChild("DeployableModels"):WaitForChild("Spikes"):Clone()
local head = char:FindFirstChild("Head")
local origin = (head.Position + (head.CFrame.LookVector.Unit * 5))
--local origin = char.PrimaryPart.Position
local direction = Vector3.new(0, -250, 0)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
params.IgnoreWater = true
local result = workspace:Raycast(origin, direction, params)
if result then
local rootPart = char:WaitForChild("HumanoidRootPart")
--
--untoggle player:WaitForChild("DeployableUsed").Value = true
deployment:PivotTo(CFrame.new(result.Position, result.Position + result.Normal))
deployment.Orientation = Vector3.new((deployment.Orientation.X), char:FindFirstChild("HumanoidRootPart").Orientation.Y , deployment.Orientation.Z)
deployment.Anchored = true
deployment.Parent = workspace
--untoggle u.InsertTag(deployment, "TeamTag", teamTag.Value)
task.wait(1)
--tool:Destroy()
task.wait(15)
deployment:Destroy()
end
end)
Image above is before. The small 1x1x1 stud part represents the ray’s origin. It is facing towards the little red part. The little red part’s CFrame is set to the slant. The slanted part is what intercepts the ray.
This is the direct code it executes to complete this.
local params = RaycastParams.new()
params.CollisionGroup = "Default"
params.FilterDescendantsInstances = {script.Parent}
params.FilterType = Enum.RaycastFilterType.Include
local ray = workspace:Raycast(script.Parent.Party.Position, script.Parent.Party.CFrame.LookVector * 100, params)
script.Parent.Part.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal)
The issue with yours is probably how the model/object is composed. Its front needs to represent the front or it will not rotate correctly. And also, with models like these, it is very recommended to set a primary part if one is not already set.
After an hour of restless coding, I finally figured out something that half works. I modified your script and had to remove some things so it didn’t error, so you might have to add some stuff back in. Basically, GoPart is just the direction of the ray but I stink at raycasting directions so I did that to be more accurate. I recommend you add that to the tool. It’s the same CFrame as the handle but tilted to the ray’s direction.
This works for the most part it just sometimes will randomly turn left or right 90 degrees so uh… I might be able to fix that later or you can code some sort of way to make sure that doesn’t happen.
local tool = script.Parent
local storage = game.ReplicatedStorage
local playerService = game:GetService("Players")
tool.Activated:Connect(function()
local char: Model = script.Parent.Parent
local player = playerService:GetPlayerFromCharacter(char)
--untoggle local teamTag = char:FindFirstChild("TeamTag")
--local char = script.Parent.Parent
local deployment = storage:WaitForChild("LolPart"):Clone()
local head = char:FindFirstChild("Head")
local origin = (head.Position)
--local origin = char.PrimaryPart.Position
local direction = script.Parent.GoPart.CFrame.LookVector * 100
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
params.IgnoreWater = true
local result = workspace:Raycast(origin, direction, params)
if result then
local rootPart = char:WaitForChild("HumanoidRootPart")
--
--untoggle player:WaitForChild("DeployableUsed").Value = true
deployment:PivotTo(CFrame.new(result.Position, result.Position + result.Normal):ToWorldSpace(CFrame.new(0, 0, -deployment.Size.Z / 2)) * CFrame.Angles(math.rad(-90), math.rad(-90), 0))
local x,y,z = script.Parent.Handle.CFrame:ToEulerAnglesXYZ()
deployment.CFrame = deployment.CFrame * CFrame.Angles(0,y,0)
deployment.Anchored = true
deployment.Parent = workspace
deployment.CanCollide = false
deployment.CanQuery = false
--untoggle u.InsertTag(deployment, "TeamTag", teamTag.Value)
task.wait(1)
--tool:Destroy()
task.wait(15)
--deployment:Destroy()
end
end)
Yoyoyoyo! This works. It does make the item hover off the ground a tiny bit, but we are jiggerin with it. We are looking at the new parts in the script, cause I want to learn how this works.
I’ll have a couple questions, hopefully you can answer them!