Orient skateboard to ground

Okay, does that really matter though?

That’s kind of the entire question right? To change the orientation you need to change the way you’re currently controlling the orientation.

You can also just directly set the CFrame every RenderStepped. Not sure if that would work or replicate well, but it’s easier.

I don’t think that would replicate to the server.

Can you provide a code example for converting the RaycastResult Normal to an orientation for the skateboard CFrame?

@PersonifiedPizza, can you please help?

Good point, you’d need to have a value for it then set the value on the clients. Here’s what I’d do:

  • Weld the skateboard to the lower torso instead of the HRP
  • Have the clients run code to update the lower torsos of characters riding skateboards.

or

  • Use a physics based approach.

I think it would look something like this:

local Workspace = game:GetService("Workspace")
local humanoidRootpart - set to HRP
local skateboard -- set to skateboard
local rayLength = 1

local function getGroundNormal()
    local raycastResult = Workspace:Raycast(skateboard.position, skateboard.CFrame.UpVector * -1 * rayLength)
    local groundNormal
    if raycastResult then
        groundNormal = raycastResult.Normal
    else
        groundNormal = Vector3.up
    end
end

local function computeOrientation(normal)
    humanoidRootpartCFrame = humanoidRootpart.CFrame

   -- angle is based on the direction the HRP is facing
   -- I honestly don't know if this is the correct formula, might have to switch some terms around
   local angle = math.arctan2(humanoidRootpartCFrame.LookVector.X, humanoidRootpartCFrame.LookVector.Y)

    return CFrame.fromAxisAngle(normal, angle).Orientation
end

Fair warning that math probably has an error some where. I’d program a quick test to see if it works before implementing it. I have to go do work stuff.

1 Like

Wow, thanks for all your help! I’ll try this out in my script later and get back to you.