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

Making a spaceship tilt towards where the player's camera is facing?

Asked by 5 years ago

I was trying to make a spaceship using BodyMovers. It is able to move like a regular vehicle, but I was having trouble making it able to tilt towards the player's camera, without which it can't fly. Below is the drive script so far anyways.

--Main Script for the spaceship
--By Ultimate_Miner64

script.Parent.MaxSpeed = script.Parent.Settings.MaxSpeed.Value

maxspeed = script.Parent.MaxSpeed

script.Parent.BodyPosition.Position = script.Parent.Position

script.Parent.BodyGyro.cframe = script.Parent.CFrame

value1 = 0

while true do

wait()

if script.Parent.Throttle == 1 then

    script.Parent.BodyPosition.Position = script.Parent.Position

    if value1 < maxspeed then value1 = value1 + script.Parent.Settings.Acceleration.Value end

        script.Parent.Driving.Value = true

        script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1

        script.Parent.Left.Value = false

        script.Parent.Right.Value = false
end

if script.Parent.Throttle == 0 then 
    local VelocityX = script.Parent.BodyVelocity.velocity.X
    local VelocityY = script.Parent.BodyVelocity.velocity.Y
    local VelocityZ = script.Parent.BodyVelocity.velocity.Z

    script.Parent.Driving.Value = false

    script.Parent.BodyVelocity.velocity = Vector3.new(VelocityX / 1.01, VelocityY, VelocityZ / 1.01)

    script.Parent.Left.Value = false

    script.Parent.Right.Value = false

end

if script.Parent.Throttle == -1 then

    if value1 > - maxspeed then value1 = value1 -script.Parent.Settings.Acceleration.Value end

        script.Parent.Driving.Value = true

        script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1

        script.Parent.Left.Value = false

        script.Parent.Right.Value = false

end

if script.Parent.Steer == 1 then

    script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,- script.Parent.Settings.TurnSpeed.Value,0)

    script.Parent.Driving.Value = true

    script.Parent.Right.Value = true

    script.Parent.Left.Value = false

end

if script.Parent.Steer == -1 then


    script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,script.Parent.Settings.TurnSpeed.Value,0)

    script.Parent.Driving.Value = true

    script.Parent.Left.Value = true

    script.Parent.Right.Value = false

end
end

Help would be appreciated.

1 answer

Log in to vote
0
Answered by 5 years ago

Managed carrying this out. So what I did was I made a RemoteEvent in ReplicatedStorage. Every .1 seconds, the script inside the VehicleSeat checks which player is sitting in the seat, then calls FireClient() on the RemoteEvent for the player who is driving the spaceship. Then I inserted a LocalScript into StarterPlayerScripts, which listens for the event. When called on this player, the LocalScript changes the CFrame of the VehicleSeatto the CFrame of the workspace.CurrentCamera.

Ad

Answer this question