I’ve been working on this for the last few days and I was about to give up so I decided to post this here and see if someone could identity a problem or send me to an approach that could fix it. Any help appreciated!
- What do you want to achieve?
I am trying to make an custom enemy lemming ai that moves towards the player once in range, and if possible I want to use Roblox physics because then I don’t need use cases for collisions. The hope is to re-create the enemy rigidbody of something like Swordburst 1 or Swordburst 2’s enemies. (outdated I know, but that is still my goal)
- What is the issue?
While I’ve gotten every mobility option to work, I believe it’ll always be stuck at 30 fps because it solely runs on the server, which leaves the visual of the enemy looking choppy and laggy:
If the quality isn’t too clear I apologize, but what is happening in the video is the enemy is moving at basically the proper speed, but the rate it’s movement happens is slower than the player’s refresh rate, which makes visual afterimages when the enemy tries to move.
- Edit: After watching the video it’s only possible to see the issue at 1080p
- Is there code to provide?
Yes, here is an example of my use of physics. I have a different segment for every other solution I’ve tried but only provided LinearVelocity for now.
Similarly I cutout everything else in my run service out except for the code related to the issue.
function Move(direction, speed)
if (RigidBody:FindFirstChild("Collider"):FindFirstChild("LinearVelocity")) then
local collider = RigidBody:FindFirstChild("Collider");
local linearVelocity = collider:FindFirstChild("LinearVelocity");
if (direction ~= Vector2.zero) then
if (direction.Magnitude > 0) then -- Normalize Direction
direction = direction.Unit;
end
local movement = direction * Vector2.new(speed, speed);
linearVelocity.PlaneVelocity = movement;
-- ^^^ setting the movement only when an actual change would occur made no difference
if (collider:GetAttribute("ForceVelocity")) then
forceVelocity = collider:GetAttribute("ForceVelocity");
local localDirection = collider.CFrame:VectorToObjectSpace(-forceVelocity);
linearVelocity.PlaneVelocity = movement + Vector2.new(localDirection.Z, localDirection.X);
end
else
linearVelocity.PlaneVelocity = Vector2.zero;
end
return;
end
end
RunService.Heartbeat:Connect(function(deltaTime)
if (#playersInRange > 0 and #Abilities ~= 0) then
-- check if ability permissions are active
if (canMove) then
-- move
Move(Vector2.new(1, 0), walkSpeed);
end
end
end)
Additionally here is the hierarchy of my enemy object:
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I’ve tried altering my code to use linearVelocity (example above), bodyVelocity, AssemblyLinearVelocity, alternating CFrame steps, ForceImpulses, basically any movement option I could think of that would create the system I am looking for.
I tried looking through a few posts on the creator hub, but nothing that really fixed the server issue, mainly just found better handles on moving the physics.
As I said at the beginning any help would be greatly appreciated, but I believe I’ve exhausted all the solutions I could find. I apologize if my code isn’t as optimized as it should be—been using Unity C# for the last year and only returned to Lua recently.
