Hi yall!
I would like to ask how to group the attack-hitPositions (collision sensor ) into these 4 sections so that my character can define which side is being attacked.
Thank you!~
Hi yall!
I would like to ask how to group the attack-hitPositions (collision sensor ) into these 4 sections so that my character can define which side is being attacked.
Thank you!~
You could assign a different material to each face of your characters collision box and check the “hitMaterial” property of your touch sensor:
https://www.blender.org/api/blender_python_api_2_77_0/bge.types.KX_TouchSensor.html#bge.types.KX_TouchSensor.hitMaterial
thanks Wendigo, but using many materials for this is abit too inefficient, with python it would be easier to control.
Typically you do not want collision on the mesh skin object, as it would interfere with the collision object (and it has way too mean faces for that purpose).
I suggest you parent invisible sensor objects to the bones. They can be very simple. This way you can detect the hit area.
To make it even simpler (following your sketch) you can have 4 invisible planes around the character as sensor objects to identify what side was attacked. You can parent these planes to the collision object (rather than bones).
You could take the position of the character and the position of the attacker and compare on hit:
attacker.position.x < player.position.x then the attacker is to the left of the player.
attacker.position.z > player.position.z then the attacker is above the player.
Sent from my iPhone using Tapatalk
just localize it,
local = hitPosition-player.worldPosition
local = player.worldorientation.inverted()*local
thanks yall!
yes localizing!! I do the same with collision for ground detection too ( if ground.hitPosition < player.pos - offset ). But i dont know how to invtert the orientation like BluePrintRandom does there o.o. thanks!
edit*
I forget to add the ()
local = player.worldorientation.inverted()*local
thanks BPR o.o
how would we divine the sections? O.O
if local.x>0 and abs(local.z)<local.x:
zone = forward
if local.x<0 and abs(local.z)<local.x:
zone = back
if local.z>0 and abs(local.z)>local.x:
zone = up
if local.z<0 and abs(local.z)>local.x:
zone = down
weee it works perfectly! Thank you (^.^)/
Very nice post, was interested in this too for fps damage zones. Headshot!
local = hitPosition - own.worldPosition
local = own.worldOrientation.inverted()*local
own['ReadOut']=str(local )
# this code assumes that y+ is local forward
# this code assumes Z+ is local up
# this code assumes the actor is 2 units tall
if abs(local.z)>(abs(local.y)+1):
if local.z>0:
own['hit']="Top"
else:
own['hit']="Bottom"
else:
if local.y>0:
own['hit']="Front"
else:
own['hit']="back"