I want to move my Mob “Enemy” character right next to the player, and it works perfectly until I try updating its position while already next to the player.
The Issue looks like this:
( its supposed to attack btw )
I have messed with my code a lot and I have had this issue for two-three days. I have printed out my positions and magnitudes between vectors, and even rewritten the code with a separate solution, but It just doesnt seem to move closer to the player.
I calculate the position with this:
local goal_from_plr = self.mele_range * 0.9 -- 90% of the range
local Directional_vector = Closest_player.Character.PrimaryPart.Position-self.Character.PrimaryPart.Position
--print(goal_from_plr,Directional_vector.Magnitude)
-- EVERYTHING WORKS HERE, BUT THE MOVETO?
if goal_from_plr*goal_from_plr < getSQvector(Directional_vector) then -- compares squares ( ranges )
local Normal = Directional_vector/Directional_vector.Magnitude
local Goal_position = Directional_vector - Normal * goal_from_plr
--print((Goal_position-Directional_vector).Magnitude)
--print((self.Character.PrimaryPart.Position+Goal_position-Closest_player.Character.PrimaryPart.Position).Magnitude)
self.Humanoid:MoveTo(self.Character.PrimaryPart.Position+Goal_position)
self:Play_animation(self.move_animation,1,true)
self.last_moveto = os.clock()
end
Example output:
I honestly dont know where the problem is coming from, but I know the character is just not moving from its position.
( btw the example output is just the code without commented print statements )