Changing angle based on speed

I am trying to make a little system for visual effects in my gliding game, and I want to make it so that the angle of the left and right pair of wings changes based on the speed that the player is going. However, I have run into some problems.

  1. When the wing Assembly is parented to the character, the main part of the wings becomes the character’s AssemblyRoot. I wouldn’t care much about this, but it prevents the character from automatically turning. There is a way that I know how to solve this, but it would create a different problem. In the wing assembly, I set the RootPriority of the wings to 50. The reason will be explained later. This however causes the results stated above.
  2. In order to change the rotation of each wing easily I had to change the RootPriority of the base part in the wings to be 50. That way the welds were changing the orientations of the correct parts, and not the base part which needs to stay in the same position.
  1. After the above problems are solved, I would like the wings to also have some sort of pivot so that they are not being rotated from the middle, and instead are being rotated from the base.
  • Example:
    image

I don’t know the best way to approach these problems, but any help is appreciated!

Just a little bump. Does anyone have a way to approach this?

i made an AoT scout cape that had a similar premise of changing based on downward speed. i made 2 things for the cape, a singular cube that was invisible, thats what was welded to my character, and i welded the cape to that cube. i used the cube as a pivot for the cape tweening the capes c0 rotational offset to get my desired affect

1 Like

It seems like you have encountered several problems with your wing system. Here are some suggestions that may help you:

  1. For the problem of the wing assembly becoming the character’s AssemblyRoot, you can try using a separate part to parent the wing assembly to instead of the character itself. This way, the wing assembly won’t interfere with the character’s movements.
  2. To change the rotation of each wing, you can try using BodyGyro objects. You can create a BodyGyro object for each wing and use the AngularVelocity property to change the rotation of each wing based on the player’s speed. You can also set the pivot point for each BodyGyro using the CFrame property.

Here’s an example code snippet that shows how to use BodyGyro objects for the wings:

local wingAssembly = -- the wing assembly
local leftWing = -- the left wing part
local rightWing = -- the right wing part

local leftGyro = Instance.new("BodyGyro")
leftGyro.P = 5000 -- adjust these values as needed
leftGyro.D = 1000
leftGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
leftGyro.CFrame = CFrame.new(leftWing.Position) * CFrame.Angles(math.rad(90), 0, 0) -- set the pivot point to be at the base of the wing
leftGyro.Parent = leftWing

local rightGyro = leftGyro:Clone()
rightGyro.Parent = rightWing

-- in a loop where you update the wings
local speed = -- calculate the player's speed
local angle = -- calculate the angle based on the player's speed
leftGyro.AngularVelocity = Vector3.new(0, angle, 0)
rightGyro.AngularVelocity = Vector3.new(0, -angle, 0)
  1. For the problem of the root priority, you can try setting the RootPriority of the wing assembly to a lower value than 50, and instead use BindToRenderStep to update the wings’ rotation. This way, the wing assembly won’t interfere with the character’s movements, and the wings will still update every frame.

Here’s an example code snippet that shows how to use BindToRenderStep to update the wings’ rotation:

local wingAssembly = -- the wing assembly
local leftWing = -- the left wing part
local rightWing = -- the right wing part

local function updateWings()
    local speed = -- calculate the player's speed
    local angle = -- calculate the angle based on the player's speed
    leftWing.CFrame = CFrame.new(leftWing.Position) * CFrame.Angles(0, math.rad(angle), 0)
    rightWing.CFrame = CFrame.new(rightWing.Position) * CFrame.Angles(0, -math.rad(angle), 0)
end

game:GetService("RunService"):BindToRenderStep("UpdateWings", Enum.RenderPriority.Character.Value - 1, updateWings)

I hope these suggestions help you solve your problems!

1 Like