Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I detect distance and orientation of part under car?

Asked by 1 year ago
script.Parent.MaxSpeed = 120
maxspeed  =script.Parent.MaxSpeed
script.Parent.BodyPosition.position = script.Parent.Position -- this is how i set the height at the start
script.Parent.BodyGyro.cframe = script.Parent.CFrame
value1 = 0
while true do
    wait()
    if script.Parent.Throttle == 1 then
        if script.Parent.Direction.Value == false then
            script.Parent.Direction.Value = false           
            if value1 < maxspeed then value1 = value1+1 end         
            script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1            
            --Making the slow down if reverse direction with speed
        else
            if value1 > 0 then
                value1 -= 1
                script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*-value1
            elseif value1 == 0 then
                script.Parent.Direction.Value = false   
            end 
        end 

    end
    if script.Parent.Throttle == 0 then
        if script.Parent.Direction.Value == false then
            if value1 > 0 then
                value1 -= 1
                script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
            end 
        else 
            if value1 > 0 then
                value1 -= 1
                script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*-value1
            end 
        end 
    end
    if script.Parent.Throttle == -1 then
        if script.Parent.Direction.Value == true then
            script.Parent.Direction.Value = true            
            if value1<31 then value1 = value1+1 end         
            script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*-value1           
        else
            if value1 > 0 then
                value1 -= 1
                script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
            elseif value1 == 0 then
                script.Parent.Direction.Value = true    
            end 
        end     
    end

    if script.Parent.Steer == 1 then
        script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,-.072,0)
    end
    if script.Parent.Steer == -1 then

        script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,.072,0)
    end
end

I’m trying to make a speeder that when its driving can float over some reason terrain as of right now I don’t have a clear idea or direction on how to do that as can be seen with how it goes up hills in the video

My initial idea was to loop this script.Parent.BodyPosition.position = script.Parent.Position and whenever there is an orientation or height change on the part below just but I'm not sure them my next idea was to ray cast under the model and get the orientation and height of the object below then adjust the BodyPosition accordingly but I’m not sure that’s possible can someone recommend a Dev tutorial a youtube video or just walk me through how I could achieve this

Video of the system so far https://streamable.com/zxu1ay

Answer this question