An issue with a 2D platformer character's velocity

Hello!
So I tried making a 2D platformer earlier this week. In this game you are a cube which is doing platform jumps and such. The cube is being moved around using BodyVelociy. Everything went smooth, but there is this huge issue. Whenever I move the cube for more than a few times, or whenever the cube spins way too much this happens:

https://gyazo.com/89d2f7aaacd8a1f2df6d2554b2024200
https://gyazo.com/5980126df0e7855fcc6617aa941f02ae

As you can probably see the movement becomes very clumsy.

This is what I use to move the cube:

if Action == "Jump" then
		cube["Jump Velocity"].MaxForce = Vector3.new(0, 10000, 0)
		cube["Jump Velocity"].Velocity = Vector3.new(0, 40, 0)
		wait(0.1)
		cube["Jump Velocity"].Velocity = Vector3.new(0, 0, 0)
		cube["Jump Velocity"].MaxForce = Vector3.new(0, 0, 0)
	elseif Action == "Left" then
		cube["Moving Velocity"].MaxForce = Vector3.new(1000, 0, 0)
		cube["Moving Velocity"].Velocity = Vector3.new(-15, 0, 0)
	elseif Action == "Right" then
		cube["Moving Velocity"].MaxForce = Vector3.new(1000, 0, 0)
		cube["Moving Velocity"].Velocity = Vector3.new(15, 0, 0)
	elseif Action == "Stop Moving" then
		cube["Moving Velocity"].MaxForce = Vector3.new(0, 0, 0)
		cube["Moving Velocity"].Velocity = Vector3.new(0, 0, 0)
	end

I tried making it so the cube doesn’t rotate with the following code:

script.Parent.Orientation = Vector3.new(0, 0, 0)

The cube doesn’t rotate when I write this, but the issue still happens.

1 Like

wow
Your game is exactly like what I was progressing on studio for the past few months

Well the problem here I guess is your movement script
try adding a value whenever a cube is moved instead of setting it
like

cube["Moving Velocity"].MaxForce = cube["Moving Velocity"].MaxForce + Vector3.new(0, 0, 0)

I’m quite don’t understand your problem as you’ve described and what you gave me but i think you should do that

My ver of the game that i worked on for a while


literally, the same bro. The only thing is my cube script works a bit more stable xd

Now that I took a look at your game I believe the issue isn’t because of my movement script. I think it’s because of the script that prevents my cube from changing its orientation/position in an unwanted way

game:GetService("RunService").Heartbeat:Connect(function()
	script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, 2)
	script.Parent.Orientation = Vector3.new(0, 0, script.Parent.Orientation.Z)
end)

why don’t you just slap 2 parts at the foreground and the background?

Just tried and the player can sometimes get stuck. I made it that way so the Z axis never changes, no matter where the player is on the map. If you don’t mind the question, how are you doing it for your game?
Edit: the Z axis is literally 2.002 when it should be 2 using the method you suggested, and the orientation also changed very slightly, making the player unable to jump

Well I used the method I mentioned, works pretty well. I can’t find any other possible solution