Hello, I’m having trouble with making a simple wall collision. I have my kinematic object player object, and my static wall object. I’ve read all sorts of answers to collision questions, but somehow nothing is working. I’ve read all the official collision info on the defold site, but I can’t figure this out.
The nightstand object is static, but it has a sprite and you can see whenever I touch it, it shoots away in whatever direction I touch it. If I keep moving, it will shoot right back to a different place on the screen. I just want to touch it, and be forced to stop.
Look at your on_input function. Is there an end to close it? Look at your on_message function. Is there one end to close the conditional, and one to close the on_message function itself?
Please post code as text in the future. It would make it easier for us to help you.
Use ``` on either side of the code to format nicely.
Thank you for the information, I’m learning as I go.
So I went back and added the ends you pointed out, but adding one or both now makes defold refuse to run a build. I’m not sure what you mean by using ` to format nicely, I’m afraid.
function init(self)
msg.post(".", “acquire_input_focus”)
msg.post("@render:", “use_fixed_fit_projection”, { near = -1, far = 1 })
self.vel = vmath.vector3() –
end
function update(self, dt)
local pos = go.get_position() –
pos = pos + self.vel * dt –
go.set_position(pos) –
self.vel.x = 0 --
self.vel.y = 0
end
function on_input(self, action_id, action)
if action_id == hash(“up”) then
self.vel.y = 150 –
elseif action_id == hash(“down”) then
self.vel.y = -150
elseif action_id == hash(“left”) then
self.vel.x = -150 –
elseif action_id == hash(“right”) then
self.vel.x = 150
end
end
function on_message(self, message_id, message, sender)
if message_id == hash(“contact_point_response”) then
go.set_position(go.get_position() + message.normal * message.distance)
end
end
end
Try this. Compare the end placements. Every conditional (if statement) needs an end to close it. Every function (on_input and on_message) needs an end to close it.
function on_input(self, action_id, action)
if action_id == hash("up") then
self.vel.y = 150
elseif action_id == hash("down") then
self.vel.y = -150
elseif action_id == hash("left") then
self.vel.x = -150
elseif action_id == hash("right") then
self.vel.x = 150
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
go.set_position(go.get_position() + message.normal * message.distance)
end
end
It was my very very last ‘end’ that was uneeded and stopped the build, so when I got rid of that, what you showed works. Sort of. That poor little nightstand sprite…
Thank you for taking the time to help me, I spent hours trying to solve this on my own as a newbie!