Jump to content

Collision based melee combat


Genebris
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...