What do you want to achieve? Keep it simple and clear!
i want the rock of the slinger to be at the center of the zombie’s head
What is the issue? Include screenshots / videos if possible!
it stays 5 inches away from the head
here’s a video:
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried searching on the devforum, scripters helpers, no result.
here is my code:
local target = findNearestTarget(newTower)
local projectile = game.ReplicatedStorage.Projectiles.Rock:Clone()
projectile.Position = newTower.Sling.Projectile.WorldPosition
projectile.Parent = workspace
for i = 0, 1,0.1 do
projectile.CFrame = projectile.CFrame:Lerp(target.Head.CFrame,i)
task.wait(0.01)
end
Great reply, I suggest either method #1, or method #2 AND method #3 due to floating point inconsistency. #2 fixes the OP’s problem #3 guarantees it ends exactly where it should.
well, i should say it used to work before,it used to go smoothly in the center of the head, but after revising my code, its like that, so there’s gotta be a solution other than that right? must say i appreciate your effort into this message.
about the first method, if the enemy was fast enough, then he would dodge the rock.
second method, i want the projectile to always track its head, as i said, it used to work before.
third method, it would look like 5 inches away from the head and then surprisingly its inside the head, i dont want it to look like that.
so, to make my message more clear i want the projectile to guarantee exactly where it should be smoothly. (center of the head)
well, im gonna wait for an another solution, if thats the only solution i have ill mark it as solved, thank you for trying to help me, i highly appreciate it.
Sorry for the late reply you are still able to use the solutions that @Paimon_osu gave you, but when using for loops I have noticed that the loops are always incorrect when starting out with 0. So what you can try doing is starting out with 1 and end off on 2, the only difference is subtracting the I value with 1 so it can be able to Lerp properly.
for i = 1, 2, 0.1 do
projectile.CFrame = projectile.CFrame:Lerp(SavedTargetCFrame,i-1) -- with one of the solutions
task.wait(0.01)
end