Search In
• More options...
Find results that contain...
Find results in...
• Create Account

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

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?

Thanks for the reply! But that doesn't seem to change anything.

Make it simple : Just animate a characters and place camera in front of head.

No approximative math formula, and How you animate and see is what you get in game.

I feel like that would limit me for when I want to run or something.

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.

• 6 years later...

Actually, your code makes an error in Math:Curve which is argument #3 is nil, number expected. But it is actually not nil. WTF

`self.swayspeed = Math:Curve(speed,self.swayspeed,10)`

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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.