Aligning a bike upwards using AssemblyAngularVelocity

  1. What do you want to achieve? Keep it simple and clear!

I am trying to create a bike system that keeps the bike upright on the X axis of a BasePart(treated as the “base” of the entire thing) that is facing 90 degrees perpendicular to the rest of the bike.


(the orientation indicator is showing what I mean)

  1. What is the issue? Include screenshots / videos if possible!
    My issue is that… well… It won’t work. The bike is either very wobbly or flings itself when I have the script running.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

My current version is the best, but it introduced problems like steering not working(I assume this has to do with the way it is rotating itself). The closest I came to solving this was using a script that aligns it using CFrame:VectorToWorldSpace(). This worked best, but no luck in stopping flinging and fixing steering.

here is a video of it.

(in the video, as I try to steer it, it does not follow.

code

align = --insert the "base" part mentioned above
RunService.Heartbeat:Connect(function()
	local val = Vector2.new(base.Orientation.X, base.Orientation.Z).Magnitude -- this is not used at the moment, ignore
	
	local xO = align.Orientation.X
	local yO = align.AssemblyAngularVelocity.Y
	local zO = align.AssemblyAngularVelocity.Z
	
	align.Massless = true
	
	local vec = align.CFrame:VectorToWorldSpace(Vector3.new(-xO, 0, 0))
	
	align.AssemblyAngularVelocity = Vector3.new(vec.X, yO+vec.Y, zO+vec.Z)
end)

any help is appreciated!

2 Likes

well i’ve never worked anything like that but you need to verify when the seat of bike get unoccupied you put the torque of the bike on low till it reaches the 0 speed in a low space to not run all the map and aswell when the bike fall to the ground you need to reset his main orientation, i can’t make any code now but that’s the idea.

1 Like

the rolling away has nothing to do with my problem, I can fix this on my own. My main concern is the rotation not working as expected.

1 Like

I am currently on my phone so I can’t exactly provide any script related help, but the most I can tell you right now is to check out Align Orientation Hope this helps.

3 Likes

I specifically do not want to use this because it locks all orientations, including the ones I want to be free.

2 Likes

instead of always trying to stay upwards, try having different target angles for steering like 70 and 110

1 Like

I don’t think you understand. The steering problem comes from the fact that the upright code does not work properly and is jittery. The solution will not solve any problems…

Ohhh, try using ApplyAngularImpulse as it instantly changes so should be more stable

1 Like

This made it worse, it just makes it vanish.(I assume it just gets flung instantly.)

So you can try this you only need one attachment in the main part/the chassis. Then create an AlignOrientation set it to the attachment and set Mode to OneAttachment, MaxTorque to somewhere around 100000 (you can adjust this as needed), then under CFrame Orientation set it to 0, 0, 90

make sure your mainpart’s orientation is facing forward to front of bike and top to sky
like the part in the image below

orient

image below shows the settings
settings

as long as you are not applying any odd forces this should work to keep it up right better

You could also try using this tutorial