Bodygyro rotation relativ to other part

Hello, i need that the bodygyro rotate the board relativ to the wedge like: in the picture.

my try:

local scanner=script.Parent   --> skateboard
local gyro=script.Parent.BodyGyro   --> bodygyro in skateboard
	

while  wait() do

	local ray = Ray.new(scanner.Position, (scanner.Position - scanner.Position+Vector3.new(0,-3,0)).unit * 300)
	local _part, position = workspace:FindPartOnRay(ray, scanner, false, true)
		if _part~=nil then
			gyro.CFrame=script.Parent.CFrame*_part.CFrame.fromAxisAngle  --> my failed try 
			 --- here i need a better line
			
		end		
end

i hope my grammer was ok (german dev)

greetings kevini44

You will be required to get the surface normal of whichever surface your board is on top of. Once you have it you can either construct a CFrame using two arguments(pos, lookAt) or just do some trigonometry.

1 Like

You could try using the surface normal, as @ScripterGo said.

 local scanner=script.Parent   --> skateboard
local gyro=script.Parent.BodyGyro   --> bodygyro in skateboard
	

while  wait() do

	local ray = Ray.new(scanner.Position, (scanner.Position - scanner.Position+Vector3.new(0,-3,0)).unit * 300)
	local _part, position, surfaceNormal = workspace:FindPartOnRay(ray, scanner, false, true)
	if _part~=nil then
       gyro.CFrame = CFrame.new(Vector3.new(), 	surfaceNormal)
	end		
end
2 Likes

If you dont want to do some raycasting normal stuff, you can try to use triangle properties. (sin, cos, tan, pythagorean theorem)

But that’s way more hacky than the normal system.

2 Likes

What if you used a BodyVelocity, and made the velocity in the lookVector direction? If you do this, you wont need a bodyGyro to move along the wedges because the bodyVelocity will cause the object conform to shape of the ramp.

2 Likes

Thank you ! :slight_smile:
https://gyazo.com/59f4e2a005375035cd34501fe18b149e

1 Like