Jump to content

Shirk

Members
  • Posts

    63
  • Joined

  • Last visited

Posts posted by Shirk

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

  2. Here is a simple tutorial for a crouch function. I wouldn't say its very good, but at least its a start for someone.

     

    Open up FPSPlayer.lua from your assets folder and navigate to the function UpdateWorld around line 230. Right after the end of

    if window:KeyHit(Key.E)
    

    add another window.KeyHit for the crouch button (In this case I used C)

    if window:KeyDown(Key.C) then
    end
    

     

    This checks to see if a key ( the C button) is pressed down within the window. In that add the following code

    self.camera:SetPosition(self.entity:GetPosition(true)+Vec3(0,self.eyeheight * 0.5,0))
    

     

    That sets the current cameras position to half the height of the players eye height.

    Just under that add

    self.moveSpeed = 2
    

     

    This sets the current move speed to 2 (your speed may differ) so you don't walk as fast as you would standing up.

     

    Now to check when the key isn't being pressed so you can continue walking at a normal speed.

    if not window:KeyDown(Key.C) then
    self.moveSpeed = 4
    end
    

     

    That almost looks like the code above, except for the addition of not before the window:KeyDown. This checks to see when the key is not pressed down, and sets the speed back to the normal walking speed.

     

    Also, can anyone help me figure out a simple viewbobbing? I dont really know where to begin.

  3. Im talking about replacing the autopistol with my own model an animations. I know how to change the viewmodel in fpsweapon.lua, but Im not sure how do go about everything else (Animations and such are already present)

  4. The health is displayed from FPSPlayer.lua, where as the ammo is displayed from FPSWeapon.lua, and Im assuming fpsweapon.lua is ran before fpsplayer.lua. Im not sure how to get the variables I used in fpsweapon.lua to work in fpsplayer.lua.

     

    Thats kind of confusing, basically Im assuming one file is ran before the other, and so the vignette is displayed above. I cant use the ammo variables defined in fpsweapon.lua in fpsplayer.lua, if I could, then I would know how to fix the problem.

  5. Alright so I got my basic HUD working, displays health and ammo. I decided to try and add vignette, which I have successfully except one small problem, the vignette layer is above the ammo layer so so it gets displayed above it, where as I would prefer it displayed below. The health displays above it (because I have the code written after the vignette in fpsplayer.lua).

     

    Here is what Im talking about. How do I get my ammo to display above the vignette layer?

    Screenshot%202014-01-13%2004.10.38.png

×
×
  • Create New...