I am currently in the process of creating a prototype game with Defold.
I have 2 objects that have sphere collision objects on them. I also have the appropriate groups/masks to detect a collision.
I have an explosion particle effect that I want to be played at the first collision point. I understand from the API reference that this is a vector3 and is obtainable by:
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
conPos = message.position
end
if message_id == hash("collision_response") and message.group == hashes.group_EnemyBullets then
print("Player hit with: ", message.group)
local url = msg.url(message.other_id)
url.fragment = "script"
local amt = go.get(url, hash("enemyBulletDamage"))
print("conPos: ", conPos)
msg.post(".", hashes.health_TakeHit, { amount = amt, contactPos = conPos })
end
if message_id == hash("collision_response") and message.group == hashes.group_Enemy then
local url = msg.url(message.other_id)
url.fragment = "script"
local amt = go.get(url, hash("enemyPhysicalDamage"))
msg.post(".", hashes.health_TakeHit, { amount = amt, contactPos = conPos })
end
end
I post āconPosā to a script that activates the particle effect and it works.
It is perfect on the first contact, but if I move object 1 and it receives another contact from object 2 the particle effect activates at object 1ās previous position.
I would assume that āconPosā would be updated with the current contact point but it doesnāt seems to be operating like that. Ideally, I would like the particle effect to activate at the point of contact no matter the location or which side of the object.
Does anyone have any thoughts on this?
Thanks for your time and attention.
EDIT: Formatting