How to make part tilt based on the parts it on

The title basically says everything, heres the issue

im currently using vectorforces to push the part upright
image

1 Like

Use raycasting to mean distance beetween ground and your part, then add force that will put part in your distance, or add a bit of force to push this

Similar to that suggestion, what I would probably do is create one ray for each bottom corner of the board (4 in total) and tilt the board based on how far the ground is from each corner. I don’t have much experience with raycasting so I don’t know if this would be possible, but I think it’s worth a try.

Yeah I would recommend what 0786ideal said, though you could get what the raycast hit and get it’s orientation then set the other part to the same orientation

I was thinking using 4 rays because if the surface is a wedge or any other part with an irregular surface, it wouldn’t work

Oh your using wedges, wait why can you just change the wedges to tilted parts

What about terrain or other meshes though?

Yep this is correct, using more rays will get a better average of the surface. A minimum of three rays is needed to form a mathematically flat plane which represents the surface.

Example project which uses three rays in this manner:

For the rotation bit you can use also this CFrame technique:

1 Like

Then use linerVelocity pulling it to the ground

Thats what im currently doing, im using hookes law to push the push the part above the ground

wouldnt it be better to only have two rays?, one in the front of the board and one in the back of the board

The reason I’m suggesting a 3rd ray is so that it tilots from side to side as well as back and forth.

I have recoded my part to use bodyGyros and bodyPositions, and i have tried using the getRotationBetween method, with 3 raycast however it doesnt really work

			local normal = Vector3.zero
			
			for _, a in pairs(rays) do
				normal = normal + a.Normal
			end
			normal = normal / 3
			
			local ray = rays[1] 
			
			local floorCFrame = getRotationBetween(currentHoverboard.CFrame.UpVector,normal,randomAxis)
			local Y = ray.Position.Y + RIDE_HEIGHT

			local position = Vector3.new(currentHoverboard.Position.X, Y, currentHoverboard.Position.Z) + (currentHoverboard.CFrame.RightVector * Movement.Value) 
			local rotation = (currentHoverboard.CFrame * CFrame.Angles(Tilt.Value, Rotation.Value, 0)) * floorCFrame
			
			currentHoverboard.BodyPosition.Position = position
			currentHoverboard.BodyGyro.CFrame = rotation

Assuming I know your issue, I’m pretty sure you can raycast it from the board downwards (which is what most approaches i’m seeing here use) and orient it towards the normal of the raycast.

This method uses AlignOrientations as far as I know but I’m pretty sure you could do something like this?

AlignOrientation.CFrame = CFrame.new(0, 0, 0) * --insert calcs for normal or stuff here