I'm trying to make a shockwave effect, and I want to make the meshpart spawn in my torso, but when I set it to the torso's position, It spawns above my head?
plr = game.Players.LocalPlayer char = plr.Character mouse = plr:GetMouse() Instance.new("ForceField", char) function die() plr = game.Players.LocalPlayer char = plr.Character local ex = Instance.new("Part", game.Workspace) local mesh = Instance.new("SpecialMesh", ex) ex.Position = char.Torso.Position mesh.MeshId = "http://www.roblox.com/asset/?id=20329976" ex.CanCollide = false ex.BrickColor = BrickColor.new("Gold") end mouse.Button1Down:connect(die)
EDIT:::: I've tried this aswell but it still doesn't work.
plr = game.Players.LocalPlayer char = plr.Character mouse = plr:GetMouse() Instance.new("ForceField", char) function die() plr = game.Players.LocalPlayer char = plr.Character local ex = Instance.new("Part", game.Workspace) local mesh = Instance.new("SpecialMesh", ex) ex.Position = char.Torso.Position + Vector3.new(0, -5, 0) mesh.MeshId = "http://www.roblox.com/asset/?id=20329976" ex.CanCollide = false ex.BrickColor = BrickColor.new("Gold") end mouse.Button1Down:connect(die)
When you set the Position
property of a part, the game will move the object above any parts in the way.
To evade this, set the CFrame
of the part instead.
So you can replace line 12 of the original code with this:
ex.CFrame = CFrame.new(char.Torso.Position) -- set it's CFrame to the torso's Position.
and you should be all set.
If you want rotation to be retained when setting the CFrame
of a part, take this piece of code and modify it to your needs. The code is suited to your question, however it would serve no use since ex
's rotation would be set to 0, 0, 0 already and setting CFrame
s has the same effect.
local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = ex.CFrame:Components() -- get the components of the CFrame of "ex". We need this to know the rotation matrix of the part. ex.CFrame = CFrame.new(char.Torso.Position, r00, r01, r02, r10, r11, r12, r20, r21, r22) -- Set ex's CFrame position coordinates to the position of the character's Torso, and then pop in the rotation matrix that ex possessed right before the teleport.