How can I create a "wiggle" effect using BodyGyro and LinearVelocity?

Hi, i’m trying to make Missiles have a sort of “wiggly” / swirl to them before they finally lock onto their target for purely cosmetic effect.


This is the result I want to achieve.

Currently, this is the code inside the function that manages the wiggle, But when ran, nothing happens and the Missile flies in a straight line before locking on.

print("Wiggle")
Gyro.CFrame = CFrame.new(Settings["CrazyWiggle"])
Velocity.VectorVelocity = Vector3.new(0,Settings["Speed"],0)

A loop calls this function, so there are no other functions that tamper with the Missile’s movement.

The “CrazyWiggle” is a Vector3 Value: Vector3.new(math.random(-25, 25), math.random(40, 50), math.random(-25, 25))

Any help is appreciated.

make a variable that can keep track of time

then you can pass the time variable into stacked noise functions to get an overall circular but also random movement along with random wiggles along that path

(incomplete pseudocode)

local t = 0
local seed = os.time() -- reset seed when you make a new missile, probably use random numbers instead of time

local function moveMissile()
  t += timePassed

  --add more/tweak numbers as needed to make it look right

  local largeMovement = math.noise(t/10+seed)*10 -- creates large arcs because 10x slower
  local smallMovement = math.noise(t + 100+seed) -- add 100 for different random numbers, changes faster but also less significant to movement

  local totalMovement = smallMovement + largeMovement

  --probably repeat for the x,y,z directions and then make a vector

end
1 Like