I’m trying to make my slime move forward as it jumps, however can’t figure out a good way. I originally tried MoveTo, but that wasn’t great, so tried BodyForce and still having no luck.
function Slime:Follow(closestPlayer)
-- Make slime jump and move forward
--self.Humanoid.WalkSpeed = self.Speed
self.Humanoid.Jump = true
--self.Humanoid:MoveTo(closestPlayer.PrimaryPart.Position)
local Direction = self.Model.PrimaryPart.CFrame.LookVector * 1000
local BodyForce = Instance.new("BodyForce")
BodyForce.Force = Direction
BodyForce.Parent = self.Model.PrimaryPart
Debris:AddItem(BodyForce, 0.25)
if self.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
self.Humanoid.StateChanged:Wait() -- Wait for slime to hit the ground
end
-- Stop movement
--self.Humanoid.WalkSpeed = 0
end
Note, I am doing this on the server, is this good? or should I be handling it all on the client?
Bodyforce is fine the force just needs to be strong enough to overcome gravity + its own mass
Apply impulse is also a great solution, wouldn’t really use bodyposition don’t recommand that
You can also just use animations to make them jump but that means they won’t really be able to go over obstacles, but in a open map where there isn’t many obstacles its a performant solution
As for your question on doing it server or not, You should actually take a look at physics network owner, in summary every object that is physics active (like non anchored parts) often change there network owner, the network owner is the one calculating the physics for that object, so for example a part dropping closely near player will have that drop calculated on the player computer
How this relates to your slime is that typically enemies should be physically owned by the nearest player, that way there is smoothness and no delay for behavior
You can read more about it here, in short the network owner of the slime should be the one that does the physics calculations and run AI behavior (which will change constantly generally speaking)
This option never occured to me. Would this be a viable solution, if I were to just rotate the slime to face player, then perform jump? The map would be predominately flat, with no real large hills or obstacles in the way.
My only concern is cause animations are client side, not all players would see, if network owner is only set to closest player?? I’ve never really messed with network ownership and know very little about physics in Roblox, so I might be thinking of that all wrong
Yes infact some games (even on the frontpage) use this method, the downside is that there isn’t much randomness to the jump and if you want to make the jump really high its possible that players can still damage the enemy by hitting the invisible rootpart (since that part doesn’t move during animation), also due to the invisible rootpart it can’t go over obstacles Although its possible to have alternative code for going over obstacles. Since the animation isn’t really physics based(sorta) its more efficient and more consistent
As for your concern, I am actually not sure what would happen if a player owns the physics ownership of a object and plays a animation, I would test that out but I believe it will replicate; Since I believe this is how the players character’s function
function Slime:Follow(closestPlayer)
-- Make slime jump and move forward
--self.Humanoid.WalkSpeed = self.Speed
self.Humanoid.Jump = true
--self.Humanoid:MoveTo(closestPlayer.PrimaryPart.Position)
local Direction = (closestPlayer.PricamyPart.Position-self.PrimaryPart.Position).unit*100
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(150000,150000,150000)
bv.Velocity = Direction
game.Debris:AddItem(bv, 0.2)
if self.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
self.Humanoid.StateChanged:Wait() -- Wait for slime to hit the ground
end
-- Stop movement
--self.Humanoid.WalkSpeed = 0
end