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

Fixing BodyGyro/BodyAngularVelocity Issues?

Asked by 8 years ago

I'm trying to create a rough outline of point to point "flight" in a Super Mario Galaxy-esque way. For those of you unfamiliar with the games, the main method of transportation between two points is using a "Launch Star" which shoots you from point A to point B in a cool looking fashion as shown here https://gyazo.com/063ce47111186adf379adf69b23920db

I want to recreate that flight path using a (most likely bigger than necessary) collection of BodyMovers. So far I have the flight path down to a degree using Rocket Propulsion and a BodyPosition (Solely for the "Reached Target" event as the Rocket Propulsion one seems to only fire once)

As you may have noticed in the gif, the top of the player's head faces their direction of flight and spins across an axis drawn from their head to their toe (Object's Y Axis)

My issues lie with making my BodyGyro objects have the head/top of torso face it's destination and having the BodyAngularVelocity rotate around the local Y Axis. I'll label the problem lines below the full scope to make it clearer.

local sling = script.Parent
local start = sling.Start
local midpt1 = sling.MidPt1
local fin = sling.Fin
local IsLaunch = false --Debounce

start.Touched:connect(function(plr)
    if plr and plr.Parent and plr.Parent:FindFirstChild("Humanoid")and not IsLaunch then
        local player = plr.Parent
        local humanoid = plr.Parent:FindFirstChild("Humanoid")
        IsLaunch = true
        local Rocket = Instance.new("RocketPropulsion", plr.Parent.Torso) --Creates RocketPropulsion
        local Gyro = Instance.new("BodyGyro", plr.Parent.Torso) --Creates BodyGyro
        local AngularV = Instance.new("BodyAngularVelocity", plr.Parent.Torso) Creates BodyAngularVelocity
        Gyro.CFrame = CFrame.new(plr.Parent.Torso.CFrame:vectorToWorldSpace(Vector3.new(1,0,0)), midpt1.Position) --Failed Attempt #1
        Rocket.Target = midpt1
        Rocket.CartoonFactor = 1
        Rocket.TargetRadius = 1
        Rocket.MaxThrust = 10000
        Rocket.MaxSpeed = 100
        Rocket.ThrustD = 1
        Rocket.ThrustP = 100000
        Rocket.TurnD = .01
        AngularV.AngularVelocity = player.Torso.CFrame:vectorToWorldSpace(Vector3.new(0,1,0))* math.rad(360)  --Failed Attempt #2
        AngularV.MaxTorque = Vector3.new(9000000,9000000,9000000)
        humanoid.PlatformStand = true
        Rocket:Fire()
        Rocket.ReachedTarget:connect(function() --Side Note is this meant to only fire once ever?
            local Position = Instance.new("BodyPosition",plr.Parent.Torso)
            Position.Position = fin.Position
            Rocket.Target = fin
            Rocket.ThrustD = 100000
            Position.ReachedTarget:connect(function() --Yet this can fire with every Position Property Change?
                AngularV.Parent = nil
                Gyro.Parent = nil
                Position.Parent = nil
                Rocket.Parent = nil
                humanoid.PlatformStand = false
                IsLaunch = false
            end)
        end)
    end
end)

First off, my BodyGyro issue lies on Line 15 Gyro.CFrame = CFrame.new(plr.Parent.Torso.CFrame:vectorToWorldSpace(Vector3.new(1,0,0)), midpt1.Position) where I attempt to have the top of the torso pointed at the target midpt1

My second issue with the BodyAngular Velocity Lies on Line 24 AngularV.AngularVelocity = player.Torso.CFrame:vectorToWorldSpace(Vector3.new(0,1,0))* math.rad(360) where I attempt to have a constant rotation around the Player's Y Axis to simulate the smooth barrel rolls done in the gif shown above.

The 3D representation of the path from Green to Blue ending at Red: https://gyazo.com/e9290ddbc64d8916871a62b7b49e20b6

The Heiarchy: https://gyazo.com/e134c17cd1c06bda33ce6db129ae7e05

Thank you for any help given and for reading through this lengthy question! This is information useful to me now, and it will be useful to me forever. If only they taught CFrames in Algebra II/Trig

~MBacon15

0
Very detailed question. User#11440 120 — 8y
0
I look at the "failed" and rejected questions for inspiration. I try to be sure to include absolutely everything that could be asked, and break it down MBacon15 97 — 8y
0
tldr UniversalDreams 205 — 8y
0
The TL;DR is right below the code block MBacon15 97 — 8y

Answer this question