What do you want to achieve? I’d like for my sword projectile to rotate 180 degrees without breaking the sword projectile.
What is the issue? The sword projectile needs to be flipped 180 degrees.
What solutions have you tried so far? Did you look for solutions on the Developer Hub? I went through so many Dev Forums on the platform during the 2 hours trying to fix it. I tried doing negative LookVectors, negative MousePositions, negative Orientations, etc.
local swordd = sword:Clone()
swordd.Parent = workspace
swordd.Anchored = true
swordd.Transparency = 0
swordd.CFrame = CFrame.new(npc.Torso.Position + Vector3.new(0,3,0))
swordd.CFrame = CFrame.lookAt(swordd.Position, mouseHit)
agentlo
(RecruitDeity)
November 19, 2021, 1:09pm
#2
taking the sword cframe and using the negative of its lookvector to make another cframe should work.
something like this:
local cf = CFrame.lookAt(swordd.Position, mouseHit)
swordd.CFrame = CFrame.lookAt(swordd.Position, swordd.Position - cf.LookVector)
Maybe you could make it face -mouseHit
?
local swordd = sword:Clone()
swordd.Parent = workspace
swordd.Anchored = true
swordd.Transparency = 0
swordd.CFrame = CFrame.new(npc.Torso.Position + Vector3.new(0,3,0))
swordd.CFrame = CFrame.lookAt(swordd.Position, -mouseHit) <<< here
tried it, althought it worked sorta, it wasn’t shooting where my mouse was. like it would shoot the same direction but it went above if you shot sorta below, then it would shoot below the mouse if you shot above
Try this instead!
local swordd = sword:Clone()
swordd.Parent = workspace
swordd.Anchored = true
swordd.Transparency = 0
swordd.CFrame = CFrame.new(npc.Torso.Position + Vector3.new(0,3,0), mouseHit)
Thanks, let me try that really quick.
Also, I forgot to add, but mouseHit is the mouse position.
Sorry, it doesn’t seem like it made a difference.
I knew something like that could happen… Could you show the code that makes it go forward?
elseif Mode == 'Sword' then
if sworddebounce == true then return end
sworddebounce = true
spawn(function()
wait(1.5)
sworddebounce = false
end)
local swordd = sword:Clone()
swordd.Parent = workspace
swordd.Anchored = true
swordd.Transparency = 0
swordd.CFrame = CFrame.new(npc.Torso.Position + Vector3.new(0,3,0))
swordd.CFrame = CFrame.lookAt(swordd.Position, mouseHit)
local params = RaycastParams.new()
local iterations = 100
params.FilterDescendantsInstances = {npc,swordd}
params.FilterType = Enum.RaycastFilterType.Blacklist
local bulletConnection
swordd.SwordLunge:Play()
bulletConnection = game:GetService('RunService').Heartbeat:Connect(function(deltaTime)
local position,nextPosition = swordd.Position, swordd.CFrame.LookVector * deltaTime * swordSpeed
local result = workspace:Raycast(position,nextPosition,params)
if result then
swordd.SwordSlash:Play()
bulletConnection:Disconnect()
local model = result.Instance:FindFirstAncestorOfClass('Model')
local human = nil
if model then human = model:FindFirstChildOfClass('Humanoid') end
if human and human.Health > 0 then
if result.Instance.Name:find('Leg') then
human.WalkSpeed -=2.5
human:TakeDamage(math.random(10,30))
elseif result.Instance.Name:find('Torso') then
human:TakeDamage(math.random(20,30))
human.WalkSpeed -=3
elseif result.Instance.Name == 'Head' then
human:TakeDamage(30)
elseif result.Instance.Name:find('Arm') then
human:TakeDamage(math.random(10,30))
end
spawn(function()
local blclone = blood:Clone()
blclone.Parent = result.Instance
blclone.Enabled = true
wait(.3)
blclone:Destroy()
end)
swordd.Position = result.Position
swordd.Parent = result.Instance
local weld = Instance.new('WeldConstraint')
weld.Part0 = swordd
weld.Part1 = result.Instance
weld.Parent = swordd
weld.Enabled = true
swordd.Anchored = false
spawn(function()
wait(10)
swordd:Destroy()
end)
else
swordd.Position = result.Position
swordd.Parent = result.Instance
local weld = Instance.new('WeldConstraint')
weld.Part0 = swordd
weld.Part1 = result.Instance
weld.Parent = swordd
weld.Enabled = true
swordd.Anchored = false
spawn(function()
wait(10)
swordd:Destroy()
end)
end
else
swordd.Position = position + nextPosition
end
iterations -= 1
if iterations < 0 then
bulletConnection:Disconnect()
swordd:Destroy()
end
end)
Maybe try multiplying the CFrame with a CFrame.Angles value.
Example:
swordd.CFrame *= CFrame.Angles(math.pi/2, 0, 0)
Note that if it doesn’t work try moving the ‘math.pi/2’ part to another section of the CFrame.Angles value
Maybe just multiply it by the negative LookVector over here:
local position,nextPosition = swordd.Position, >>> -swordd.CFrame.LookVector <<< * deltaTime * swordSpeed
I’m also gonna be offline for a long time because school is in like 30 mins and yeah.
done that before, that just makes it go forward, but it doesn’t change the direction
agentlo
(RecruitDeity)
November 19, 2021, 1:23pm
#15
Id try this before you go
local cf = CFrame.lookAt(swordd.Position, mouseHit)
swordd.CFrame = CFrame.lookAt(swordd.Position, swordd.Position - cf.LookVector)
I’ll try when I’m back, I have to get ready for school.
Have you tried this @illuminati6767 ?
(Sorry, look at the post I replied to)
I’ve got to go, I’ll reply in a couple hours.
Exactly! Your sword points correctly with the change in the CFrame.lookAt you did, and with this modification it will then go to the right direction aswell! (i think :p)