Help with positioning

hi, so I’m using howtoroblox’s tutorial on how to make ice magic, I followed everything and it was perfect. But my problem is it spawns at the bottom, at y 0. I thought it would be at the Y that my character’s legs are at. How would I make this work??
https://gyazo.com/2068689cd7576bdf4758601e16a99cac

return function(plr)
	local tweenservice = game:GetService("TweenService")
	local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
	local mouse = plr:GetMouse()
	local mouseCF = mouse.Hit
    local start = CFrame.new(plr.Character.HumanoidRootPart.Position, mouseCF.Position)
	-- local goal = start.LookVector * 70
	local spikesNum = math.random(8, 15)
	local shardIncrements = 70 / spikesNum
	for i = 1, spikesNum do
		local newSpike = script.IceSpike:Clone()
		newSpike.Anchored = true
		newSpike.CanCollide = false
	    local x, y, z = math.random(30, 50)/30 * i, math.random(30, 50)/30 * i * 2, math.random(30, 50)/30 * i
		newSpike.Size = Vector3.new(0, 0, 0)
		local pos = plr.Character.HumanoidRootPart.Position + start.LookVector * (shardIncrements * i)
		newSpike.Position = Vector3.new(pos.X, 0, pos.Z) -- the line where it sets the position of the spike
		local newSize = Vector3.new(x, y, z)
		local newPos = newSpike.Position + Vector3.new(0, y/2.5, 0)
		local tween = tweenservice:Create(newSpike, tweeninfo, {Size = newSize, Position = newPos})
		newSpike.Parent = workspace
		tween:Play()
		local charactersHit = {}
		
		 local parts = workspace:GetPartsInPart(newSpike)
		
		--[[ if parts:IsA("BasePart") then
			if parts.Parent:IsA("Model") then
				if parts.Parent["Humanoid"] then
					local hum = parts.Parent:WaitForChild("Humanoid")
					hum:TakeDamage(30)
				end
			end
		end  --]]
		
		coroutine.resume(coroutine.create(function()
			wait(3)
			local reverseTween = tweenservice:Create(newSpike, tweeninfo, {Size = Vector3.new(0, 0, 0), Position = Vector3.new(pos.X, 0, pos.Z)})
			reverseTween:Play()
			reverseTween.Completed:Wait()
			newSpike:Destroy()
		end))
		wait(math.random(1, 100)/1000)
	end
	plr.Busy.Value = false
	print("z move done!")
end

When you are setting the position of the spike, you are setting the Y value of the vector to 0, setting the Y of the spike relative to the world to 0. If you wanted it to be at your character’s feet, you could just get the position of the character (which is already declared as pos), and subtract it by 3 (which would reach the feet of a default character). So something like this:

local pos = plr.Character.HumanoidRootPart.Position + start.LookVector * (shardIncrements * i)
newSpike.Position = Vector3.new(pos.X, pos.Y - 3, pos.Z)

Well, you see, it goes to where your mouse is so for example if my mouse is like high up, it also goes high up, i cant explain so here’s a gif: https://gyazo.com/19ca9b5c8b739d331f31c7e16926fb50

You could set the Y of the mouse position to be equal to the Y of the HumanoidRootPart, making the script think the mouse is on the same level as the rootPart and making the ice go along the ground, like this (I might have messed something up though, I do that often lol):

local mouseCF = mouse.Hit
local mousePos = Vector3.new(mouseCF.Position.X,plr.Character.HumanoidRootPart.Position.Y,mouseCF.Position.X)
local start = CFrame.new(plr.Character.HumanoidRootPart.Position,mousePos)

I dont know what happened but this happened https://gyazo.com/6e8386930731e31d4a47318971496255

Well, it looks like it is firing towards your mouse position most of the time? Mouse.hit has a tendency to hit behind the player for some reason, so that could be it for the ice spike that went backward.

Oh well that’s depressing, eitherway I tried making it so it just summons the spikes in front of the player but my methods just dont work, my method is just setting it to the position of the player. Do you perhaps know how I could do that?

Oh, if you just want it to fire in the direction the player is facing, you could just do:

local pos = plr.Character.HumanoidRootPart.Position + plr.Character.HumanoidRootPart.CFrame.LookVector * (shardIncrements * i)

I take that back, that would allow you to curve the ice spikes. Do something like this instead:

local start = plr.Character.HumanoidRootPart.CFrame
1 Like

I was about to reply that, but this worked, thank you so much!

OH GOD IM SORRY THIS

local mousePos = Vector3.new(mouseCF.Position.X,plr.Character.HumanoidRootPart.Position.Y,mouseCF.Position.X)

WAS SUPPOSED TO BE

local mousePos = Vector3.new(mouseCF.Position.X,plr.Character.HumanoidRootPart.Position.Y,mouseCF.Position.Z)

I ACCIDENTALLY MADE THE 3RD VALUE USE X INSTEAD OF Z
anyways that should have fixed that problem lol

1 Like

Hey, sorry if this is a bit late but the spike doesnt face the same direction the player is facing

Edit: some of the spikes float, they’re supposed to stick to the ground. https://gyazo.com/fb40b05efb6fd70bd8b896bb95b35608

You could probably set the y orientation of the spike to the y orientation of the character after you set the position, like:

local start = CFrame.new(plr.Character.HumanoidRootPart.Position, mouseCF.Position)
local orientation = plr.Character.HumanoidRootPart.Orientation --set the orientation in a variable

and then:

newSpike.Position = Vector3.new(pos.X, 0, pos.Z) -- the line where it sets the position of the spike
newSpike.Orientation = orientation

I don’t know the original orientation of the spike, so offset the orientation (like: orientation + Vector3.new(0,[insert angle], 0)) a bit if the spikes are facing sideways or something.

About the not sticking to the ground, the ice spikes cast at the same height of the player, so if the player casts the spell while in the air, the ice spikes will appear in the air. You could fix this by raycasting downwards, but that would be a lot more complicated and require large changes to the script.

If you want to try raycasting:
https://developer.roblox.com/en-us/api-reference/function/WorldRoot/Raycast

I’ve tried the orientation thingy, but it still faces the wrong way https://gyazo.com/959ce5e0113b96e8b8cb90e5ec015ffb

Oh whoops, I forgot it fires towards the mouse instead of in front of the player. I guess you could do something like (Assuming you are using the mousePos variable I gave in the earlier reply):

newSpike.Position = Vector3.new(pos.X, 0, pos.Z) -- the line where it sets the position of the spike
newSpike.CFrame = CFrame.new(newSpike.Position, mousePos) 
newSpike.Orientation = newSpike.Orientation + Vector3.new(0,-90,0) -- i think this is the offset

Basically, CFrame.new can also take a second position argument, which is the position the created CFrame faces towards.

Still faces the wrong way, plus allows me to change the rotation when I move my mouse
https://gyazo.com/afc2adb9f712b25f0845237e4bba8400

newSpike.Position = Vector3.new(pos.X, 0, pos.Z) -- the line where it sets the position of the spike
newSpike.CFrame = CFrame.new(newSpike.Position, mousePos) 
newSpike.Orientation = newSpike.Orientation + Vector3.new(0,90,0) 

Added something that should offset it by 90 degrees after it is placed.

https://gyazo.com/7a909b855b24206f4e83ac561cec0b31
I think what I meant is like, it faces upfront and not sideways or the opposite way.
like this: image

I think I made it face the wrong way lol
If I don’t get it correct, you could just play around with the offset values until it is correct.

newSpike.Orientation = newSpike.Orientation + Vector3.new(0,-90,0) 

That would make it so it faces -90 degrees everytime u do the move and not the direction the player is facing.