Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Head bobbing problem

Recommended Posts

Ive been trying to figure out why my headbobbing only really works when moving in a certain direction; east to west.

Heres a video of the problem. Notice that when I move in the direction of the crawler that it is working fine, but when I turn 90 degrees either way it stops working correctly.



here is my code

function Script:Headbob()
local bob = 0;
local jumpbob = 0
local speed = math.max(1,self.entity:GetVelocity():xz():Length())
if self.entity:GetAirborne() then speed = 0.1 end
self.swayspeed = Math:Curve(speed,self.swayspeed,10)
self.swayspeed = math.max(0.5,self.swayspeed)
self.amplitude = math.max(2,Math:Curve(speed,self.amplitude,20))
self.timeunits = self.timeunits + self.swayspeed*4*Time:GetSpeed()
local sway = math.sin(self.timeunits/120.0) * self.maxswayamplitude * self.amplitude
bob = (1-math.cos(self.timeunits/60.0)) * self.maxswayamplitude * 0.1 * self.amplitude
local campos = self.camera:GetPosition(true)

self.smoothedposition.x = campos.x
self.smoothedposition.y = Math:Curve(campos.y,self.smoothedposition.y,2)
self.smoothedposition.z = campos.z

self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(sway*self.entity.scale.x,self.eyeheight + bob * 0.1,0))


Link to post
Share on other sites

Change this:

self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(sway*self.entity.scale.x,self.eyeheight + bob * 0.1,0))

To this:


self.camera:Translate(sway*self.entity.scale.x,self.eyeheight + bob * 0.1,0)


S.T.A.L.K.E.R. fan much?

Link to post
Share on other sites
  • 6 years later...

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.

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...