KossmoZ
(KossmoZ)
September 20, 2019, 2:51pm
#1
I’m currently attempting to make my ships tilt as they turn / rotate in-game using BodyGyro.
I’m looking at doing this because I recently changed the Piloting system to be Client controlled as opposed to Server, as a result of this only the Pilot can see the ship tilting in-flight now.
My current method involves using a Weld and a root part, in which the C0 is tweened when rotating, allowing it to tilt. But because of this now being managed by the client, Players no longer see the tilting in action.
Any suggestions on how I can manage this using BodyGyros instead?
Current / Expected:
https://gyazo.com/49dd32e1b6374f52f602e0969f5d388a
2 Likes
KossmoZ
(KossmoZ)
September 21, 2019, 11:10am
#2
UPDATE:
Changed the steer of the ship to use BodyGyro as opposed to BodyAngularVelocity, however - Upon trying to achieve the tilt this is the end result.
https://gyazo.com/a8da7abfa25a0fe4296a6b6ca2e5396f
Im going to need you to post some code.
1 Like
KossmoZ
(KossmoZ)
September 21, 2019, 11:25am
#4
This is the first attempt of the code:
if Command_Seat.Steer == -1 then
System.BodyMovers.BodyGyro.CFrame = System.Exterior.Root.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(15), 15)
elseif Command_Seat.Steer == 0 then
System.BodyMovers.BodyGyro.CFrame = System.Exterior.Root.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
elseif Command_Seat.Steer == 1 then
System.BodyMovers.BodyGyro.CFrame = System.Exterior.Root.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(15), 15)
end
This is the second attempt of the code:
if Command_Seat.Steer == -1 then
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, math.rad(15), 0) * CFrame.Angles(0, 0, math.rad(15))
elseif Command_Seat.Steer == 0 then
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, math.rad(0), 0) * CFrame.Angles(0, 0, math.rad(0))
elseif Command_Seat.Steer == 1 then
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, math.rad(-15), 0) * CFrame.Angles(0, 0, math.rad(-15))
end
None of which were the desired result.
nooneisback
(nooneisback)
September 21, 2019, 11:35am
#5
The issue is that you are adding onto the already transformed CFrame. The rotations pile up and you have this weird orientation as a result. You could try getting the Y component of the orientation and combining it with the desired inclination though I haven’t worked with matrices in a long time so I’d have to check for myself.
local OrientationCFrame = CFrame.Angles(0,CurrentY,0)*CFrame.Angles(0,0,DesiredIncl)
Don’t forget to transform deg to rad.
6 Likes
KossmoZ
(KossmoZ)
September 21, 2019, 11:38am
#6
So using this method it’d be: (?)
System.BodyMovers.BodyGyro.CFrame = CFrame.new(0,System.Exterior.Root.Orientation.Y,0)*CFrame.new(0,0,15)
KossmoZ
(KossmoZ)
September 21, 2019, 11:45am
#7
As shown about with my first version -
That uses BodyAngularVelocity to turn Left / Right and a seperate ‘Root’ Part with a Weld that Tweens the C0 when the Steer property is changed.
Because I changed the controls the be client-side, the tilting is now only visible to the actual Pilot.
As the Part’s NetworkOwner is set to the Pilot - I’m planning on using BodyGyro to achieve that same effect where it can both turn left / right as well as tilt in the process.
1 Like
nooneisback
(nooneisback)
September 21, 2019, 11:59am
#8
Oops. I’ll fix my original post.
KossmoZ
(KossmoZ)
September 21, 2019, 12:04pm
#9
nooneisback:
local OrientationCFrame = CFrame.Angles(0,CurrentY,0)*CFrame.Angles(0,0,DesiredIncl)
I may of definitely of done this wrong, but:
System.BodyMovers.BodyGyro.CFrame = System.Exterior.Root.CFrame * CFrame.fromEulerAnglesXYZ(0, math.rad(15), 0)
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0,System.Exterior.Root.Orientation.Y,0)*CFrame.Angles(0,0,math.rad(15))
1 Like
nooneisback
(nooneisback)
September 21, 2019, 12:14pm
#10
What is the result though? I have no way to know what is happening.
2 Likes
KossmoZ
(KossmoZ)
September 21, 2019, 12:20pm
#11
nooneisback:
CFrame.Angles(0,CurrentY,0)*CFrame.Angles(0,0,DesiredIncl)
if Command_Seat.Steer == -1 then
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, CurrentY, 0)*CFrame.Angles(0, 0, math.rad(-15))
CurrentY = CurrentY - .25
elseif Command_Seat.Steer == 0 then
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, CurrentY, 0)*CFrame.Angles(0, 0, 0)
CurrentY = CurrentY
elseif Command_Seat.Steer == 1 then
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, CurrentY, 0)*CFrame.Angles(0, 0, math.rad(15))
CurrentY = CurrentY + .25
end
https://gyazo.com/8a8139cfc01e0e2200c6f83783cab564
KossmoZ
(KossmoZ)
September 21, 2019, 12:27pm
#12
Turns out your original method had worked - I was just going the wrong way about it!
Thank you so much!
https://gyazo.com/a2b9abefc615ae6f51a6ac9af4d4cbc0
if Command_Seat.Steer == -1 then
CurrentY = CurrentY + 1
CurrentZ = 15
elseif Command_Seat.Steer == 0 then
CurrentZ = 0
elseif Command_Seat.Steer == 1 then
CurrentY = CurrentY - 1
CurrentZ = -15
end
System.BodyMovers.BodyGyro.CFrame = CFrame.Angles(0, math.rad(CurrentY), 0) * CFrame.Angles(0, 0, math.rad(CurrentZ))
9 Likes
nooneisback
(nooneisback)
September 21, 2019, 12:27pm
#13
This seems about right. Try messing around with MaxTorque and P. The result seems correct, but not visible enough.
Wyzloc
(Wyzloc)
September 21, 2019, 12:28pm
#14
Looks visible to me, good job!
3 Likes
Hello, sorry to bump.
In my current script it works fine:
local Command_Seat = script.Parent
CurrentY = Command_Seat.BodyGyro.CFrame.Y
CurrentZ = Command_Seat.BodyGyro.CFrame.Z
while wait() do
if Command_Seat.Steer == -1 then
CurrentY = CurrentY + 1
CurrentZ = 15
elseif Command_Seat.Steer == 0 then
CurrentZ = 0
elseif Command_Seat.Steer == 1 then
CurrentY = CurrentY - 1
CurrentZ = -15
end
Command_Seat.BodyGyro.CFrame = CFrame.Angles(0, math.rad(CurrentY), 0) * CFrame.Angles(0, 0, math.rad(CurrentZ))
end
But since I try to avoid while loops since it slows my server down I tried this and it doesn’t work resulting in weird rotation
local Command_Seat = script.Parent
CurrentY = Command_Seat.BodyGyro.CFrame.Y
CurrentZ = Command_Seat.BodyGyro.CFrame.Z
Command_Seat:GetPropertyChangedSignal("Steer"):Connect(function()
if Command_Seat.Steer == -1 then
CurrentY = CurrentY + 1
CurrentZ = 15
elseif Command_Seat.Steer == 0 then
CurrentZ = 0
elseif Command_Seat.Steer == 1 then
CurrentY = CurrentY - 1
CurrentZ = -15
end
Command_Seat.BodyGyro.CFrame = CFrame.Angles(0, math.rad(CurrentY), 0) * CFrame.Angles(0, 0, math.rad(CurrentZ))
end)
Is there a way around the loop or to fix the second one? or is it ok to have the loop I’m not entirely sure if its that bad.
Thanks, sorry again.