I’m making a tower defense game, and I have a tower that shoots projectiles, the issue I have is that it shoots it where the enemy WAS, not where it IS.
I tried using npc:GetPivot().LookVector * npc.Humanoid.WalkSpeed(multiplied by the walkspeed since its measured in studs per second), for the location, which works perfectly if its straight, but unfortunately it turns, so it shoots a very strange way.
also, I can’t use the waypoints(from pathfindingservice:CreatePath()), as they generate a path randomly, and I don’t actually know the route until they already have spawned, and also the waypoints are only on corners, as I set the waypoint spacing to math.huge, which means it they will only be at turning/jumping locations
is there a good method to predict the movement of the enemy, or should I just try to not visually have projectiles?
Well if you expand the paths just make a script that checks where the route is with a variable or something. And then check where the path is. So basically just get the position of the path and then set the waypoints on that position(The corners I think, not sure.).
well as I said, I had to set the waypoint spacing to math.huge, which makes the waypoints only where they need to turn or jump, and if it’s not math.huge, it stutters, and eventually stops entirely
I found a method that kind of works, using align position, where I update the position every heartbeat, but it slows down weirdly when it gets closer robloxapp-20220316-11531.wmv (1.2 MB)
which is not optimal
local npcRoot = npc.PrimaryPart.CFrame --//Like their root part
local towerBarrel = tower.Barrel.CFrame
local offset = npcRoot.LookVector.Unit*npcWalkSpeed
local direction = ( (npcRoot*offset).Position - towerBarrel.Position).Unit
I’m pretty confused as to what results it yields, could you show me??
You won’t be having trouble. I just tested it and it doesn’t slows down.
It makes it slow down because you set it to OneAttachment, I have set it to TwoAttachment and it works without slowing it down. But if I use OneAttachment like you have it does slows down at the end.
Do you have 2 Attachments? Cause in order to set the mode to TwoAttachment you need to have 2 attachments in this case I the portal and the NPC. Allthough I think it might sabotage your waypoints.
You’re solution actually still works, it slows down very slightly, but all I had to do was set the position to subtract the lookvector of the npc since I check the proximity for damage so if it goes through its fine