Jump to content

Genebris

Members
  • Posts

    517
  • Joined

  • Last visited

Posts posted by Genebris

  1. Yes, I guess instead of this collider box I can place two pivots and launch a cylinder raycast beetwen them every frame, nice idea, thanks. But this probably won't work if the whole sword is inside the enemy mesh. Will test it later, don't have time now.

  2. I'm guessing you are getting that lag because you are setting the position/rotation in the UpdatePhysics() function which is called at a specific rate (ie not as fast as possible). Try doing that in UpdateWorld() and see if you get the same lag.

    Yes, I think so too, but in updateworld it doesn't work at all.

    Have just checked it again, in UpdateWorld the trigger lags like hell and flies away from the sword.

  3. I have made a simple collision based melee combat system, it seems to work fine, you can take it if you want. But I also have a question about it. As you can see on the video below, weapon collider moves with a small latency, can I do anything to make it follow weapon model faster? Or is it the best result I can get? (Sorry for the video quality)

     

    Here is the main code:

     

     

    function Script:Start()

    if player.weaponTrigger then player.weaponTrigger:Release() end

    player.weaponTrigger=self.entity

    player.armR.script.weaponTrigger=self.entity

    self.parent=self.entity:GetParent()

    self.bloodPoint=self.parent:FindChild("BloodPoint")

    self.entity:SetParent(nil)

    self.entity:SetGravityMode(false)

    self.entity:SetMass(1)

    self.entity:SetCollisionType(10)

    self.entity:SetPickMode(0)

    self.parent:SetPickMode(0)

    self.entity:SetKeyValue("noPick","true")

    end

     

    function Script:UpdatePhysics()

    local p = self.parent:GetPosition(true)

    local r = self.parent:GetRotation(true)

    self.entity:PhysicsSetPosition(p[0], p[1], p[2], 1)

    self.entity:PhysicsSetRotation(r[0], r[1], r[2])

    end

     

    function Script:Collision(entity, position, normal, speed)

    if not self.ready or entity==player.entity then return end

    local d=Time:GetCurrent()-self.startTime

    if d>50 then

    if self.bloodPoint then

    position=self.bloodPoint:GetPosition(true)

    else

    position=nil

    end

    player.armR.script:Hit(entity, position, normal)

    else

    App:Notification("Attack failed "..d)

    end

    player.armR.script.animationmanager:ClearAnimations()

    player.armR.script:Idle()

    self.ready=false

    end

     

     

    The idea is very simple: when player equips sword the sword prefab is being loaded and attached to the hand bone. The sword prefab has a sword model and an extra object with collider (WeaponTrigger). Also there is a blood point in the prefab to create blood particles in it's coordinates, but that doesn't matter. In WeaponTrigger start function this entity is being separated from the sword model and in UpdatePhysics it's being moved to the sword model position.

    Obviously, when this trigger collides with something we can hurt it and stop attack animation.

  4. Ok, so you were using Rick's weapon loading mechanism with with weapons that already have this mechanism programmed. In the end of the start function of FPSPlayer script you have these lines:

    if self.weaponfile~="" then
    		 local prefab = Prefab:Load(self.weaponfile)
    		 if prefab~=nil then
    				 if prefab.script~=nil then
    						 self:AddWeapon(prefab.script)
    				 else
    						 prefab:Release()
    				 end
    		 end
     end
    

    This is how loading of these weapons work (they have everything else in their start function). And this is what your LoadWeapon function should be. So I simply commented out your LoadWeapon function and added new one with this code. And I have commented out this code from player start function so the weapon won't be loaded at start twice.

    Here is the link to modified FPSPlayer.lua: http://pastebin.com/UNyPvtim

  5. Are you sure you have correct file path and correct prefab? "weapon file loaded" shows and it means something is loaded. If you want to use teamviewer ask Rick or someone else, I can't help you with that, sorry.

    Or send me the whole project dirrectory and I'll look into it tomorrow.

  6. Your LoadWeapon function:

    function Script:LoadWeapon()
       --Load the default weapon, if one is set
       if self.weaponfile=="" then
           local entity = Prefab:Load (self.weaponfile)
           if entity ~=nil then
               System:Print("weapon file loaded")
               if entity.script~=nil then
                   entity.script:Start()
                   entity.script.player = self
                   self.weapon = entity.script
                   self.weapon.entity:SetParent(self.camera)
                   self.weapon.entity:SetRotation(0,0,0)
                   if self.weapon.offset~=nil then
                       self.weapon.entity:SetPoint(self.weapon.offset)
                   else
                       self.weapon.entity:SetPosition(0,0,0)
                   end
               end
           end
       end
    end
    

    The second line is:

    if self.weaponfile=="" then
    

    Shouldn't it be ~= instead of ==?

    Also, I suggest you making it like this:

    if self.weaponfile=="" then return end
    

    This will stop the function if wapon file path is empty.

  7. This works, thank you. But I have a different problem now: my trigger now detects collision only with models, not with brushes. I have a default shelf model and a brush primitive. They both have collision type scene and GetCollisionType() returns 2 for both of them, but my trigger detects collision with brush only if it has mass or script attached. Can I do anything about it?

  8. I'm trying to make a trigger that will detect collisions with characters, scene and props, but it seems like trigger response type works only for characters.

    Collision:SetResponse(10, Collision.Scene, 2)
    Collision:SetResponse(10, Collision.Prop, 2)
    Collision:SetResponse(10, Collision.Character, 2)
    self.entity:SetCollisionType(10)
    

    This makes my entity work as trigger for characters, but it collides with props and scene. Using 1 as a third parameter makes it collide with everything, using 0 makes it collide with nothing.

    Is it a bug or intended? Or am I doing something wrong?

×
×
  • Create New...