Genebris Posted January 5, 2015 Share Posted January 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 5, 2015 Share Posted January 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
Genebris Posted January 5, 2015 Author Share Posted January 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
shadmar Posted January 5, 2015 Share Posted January 5, 2015 I think you can just parent the "sword" to the wristbone in start(), no need to use PhysicsSet...() at all. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Genebris Posted January 5, 2015 Author Share Posted January 5, 2015 No, it won't detect collisions then. At least it wasn't for me. Quote Link to comment Share on other sites More sharing options...
shadmar Posted January 5, 2015 Share Posted January 5, 2015 Yes you are correct, gave it a try aswell, I could't get it to work either. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
DerRidda Posted January 5, 2015 Share Posted January 5, 2015 Have you tried playing with SetPhysicsDetail()? http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/world/worldsetphysicsdetail-r785 1 Quote Link to comment Share on other sites More sharing options...
shadmar Posted January 5, 2015 Share Posted January 5, 2015 Might be better to do raytesting or aabb intersection tests instead of physics. 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Genebris Posted January 5, 2015 Author Share Posted January 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 5, 2015 Share Posted January 5, 2015 Get the bounding box of the sword and then do a ForEachEntityInAABBDo() to see what it's colliding with. 1 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.