Jump to content

Head bobbing problem


Shirk
 Share

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))
self.entity:Translate(self.offset.x,self.offset.y,self.offset.z)

end

Link to comment
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:SetPosition(self.entity:GetPosition(true))

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

 

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

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Nope.

When you run or do something else, your character have animated armsame for jumping, climbing.

What you have to do at final is just attach weapon to the hands and put camera in front of head.

The camera will just do as same as player head.

Stop toying and make games

Link to comment
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.

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.

 Share

×
×
  • Create New...