Shirk Posted January 25, 2014 Share Posted January 25, 2014 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 Quote Link to comment Share on other sites More sharing options...
Josh Posted January 25, 2014 Share Posted January 25, 2014 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? Quote 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 More sharing options...
Shirk Posted January 25, 2014 Author Share Posted January 25, 2014 Thanks for the reply! But that doesn't seem to change anything. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted January 26, 2014 Share Posted January 26, 2014 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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Shirk Posted January 26, 2014 Author Share Posted January 26, 2014 I feel like that would limit me for when I want to run or something. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted January 26, 2014 Share Posted January 26, 2014 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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
WD-40 Posted September 20, 2020 Share Posted September 20, 2020 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) Quote Link to comment Share on other sites More sharing options...
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.