Jump to content

Recommended Posts

Posted

Hey Ultra Engine community!

I'm just a beginner messing around with Lua in Ultra Engine, and I wanted to share a quick head bobbing (wobble) effect I added to my FPSPlayer script!

I added the wobble in the FPSPlayer:Update() function, tweaking the camera’s Y position with a sine wave. Here’s the gist:

  1. Setup in Start():
    self.bobFrequencyWalk = 2.0 -- 2 steps/sec self.bobAmplitudeWalk = 0.05 -- 5cm bounce self.bobFrequencyRun = 3.0 -- 3 steps/sec self.bobAmplitudeRun = 0.1 -- 10cm bounce
     
     
    These set how fast and far the camera bobs. I used World:GetTime() (check the World docs) for timing.
  2. Bobbing in Update():
    local localPos = Vec3(0, h, 0) if onGround and self.movement:Length() > 0 then local bobFrequency = self.running and self.bobFrequencyRun or self.bobFrequencyWalk local bobAmplitude = self.running and self.bobAmplitudeRun or self.bobAmplitudeWalk local timeInSeconds = world:GetTime() / 1000.0 local bobPhase = math.sin(2 * math.pi * bobFrequency * timeInSeconds) * bobAmplitude localPos.y = localPos.y + bobPhase end self.currentcameraposition = TransformPoint(localPos, entity, nil) self.camera:SetPosition(self.currentcameraposition, true)
     
     
    • Logic: Only bob when grounded (Entity:GetAirborne()) and moving (self.movement).
    • Sine Wave: math.sin makes the smooth bounce, using time in seconds and frequency in Hz.
    • Camera: Camera:SetPosition and TransformPoint (Camera, Vec3) move the camera smoothly.

This is a starting point! 😅 It’s clunky and has bugs, but I’ll keep tweaking it. Try adjusting the numbers or adding side-to-side bobbing with math.cos. Maybe use World:Pick (World:Pick) for ground materials later! ^^ I’ll use this as my base and share updates—feel free to improve it and show me what you got!

image.gif.c444b98a454ec73abaefb979275fc86a.gif

 

 

FPSPlayer.lua

  • Like 2
  • Iron-Vale changed the title to Smoother Lua Player Script (maybe)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...