Help with ball movement

So, i’m making a game where the player is a ball.

I can’t figure out the movement, but I think when you move, you would apply a force in that direction? I have a vague idea of how to do it, but I want it to be compatible with mobile, too, and that’s really confusing me.

1 Like

Yes, thats exactly what you do. You get the player’s movement, then add it to the ball.

1 Like

Okay, but the player model is completely deleted when they spawn and the camera subject is set to a ball with the player’s face. Since the player model is completely deleted, how can I get the player’s movement?

player movement comes from their humanoid. you dont need to do any extra work at all to get them to move, just put a humanoid in the ball model

Just like @xXSanrioSlayer99 said, a player’s movement comes from their humanoid. The Humanoid has a property called MoveDirection which determines, as a unit vector, the direction a player is moving in. You can access the Magnitude property to see if it is greater than 0 to determine if there is active movement without having to rely on their HumanoidStateType.

2 Likes

I’m actually currently working on a project where you’re a ball, and I’m using linear velocities. Or, you could use VectorForces. For both of these, you can check whenever the Humanoid.MoveDirection changes. When it does, set the mover’s force/magnitude property to the movedirection. You can even multiply it by some value to incorporate speed into the mix.

local vectorforce = character.HumanoidRootPart.VectorForce
local customwalkspeed = 1

character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
    vectorforce.Force = character.Humanoid.MoveDirection * customwalkspeed
end)

One thing to know about specifically vector forces, they don’t stop speeding you up. It’s a constant increase of velocity. So depending on the physics of your game, you can get some really cool physics if you use this, although if they just hold w, they’ll keep going faster and faster until they hit something.

With linear velocites, they speed up and up until they hit a certain velocity. It’s whole purpose is to maintain a certain velocity. The problem with this is that if you’re already traveling in that direction, e.g. conveyor belt, rocket ship, you won’t really move. That’s because your velocity is already in that direction. The pro is that they STOP moving you once you hit that velocity. You don’t have to worry about balls flying at 160 mph.

1 Like

Thanks! How can I get the humanoid if the player model is deleted, though?

then don’t delete the humanoid, put the character model somewhere inconspicuous in the workspace. If you don’t to do that, you can also get the direction vector from the control module:

local playermodule = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule)
local controls = PlayerModule:GetControls()
local movevector = controls:GetMoveVector() -- returns the latest direction the player is moving in.

simply use this, and then you can get the real direction by rotating it in the direction the camera is facing:

local x, y, z = camera.CFrame:ToOrientation()
local realmovevector = movevector * CFrame.Angles(0, y, 0)

This is not tested, but it should work.

Thanks! When I get a chance, I’ll try it!

1 Like