Iron-Vale Posted May 24 Posted May 24 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: 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. 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! FPSPlayer.lua 2 Quote
Recommended Posts
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.