So, I’m messing around with tilemaps, and i’m trying out kinematic collisions. For some reason, it collides when using dynamic, but my method of preventing movement when colliding won’t work. Its a top-down kind of game, just for context. My player code:
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 })
self.i = vmath.vector3()
self.p = go.get_position()
self.speed = 3
end
function update(self)
self.p = go.get_position()
self.p = self.p + self.i
go.set_position(self.p)
self.i = vmath.vector3()
end
function on_input(self, action_id, action)
if action_id == hash("a") then
self.i.x = -self.speed
elseif action_id == hash("d") then
self.i.x = self.speed
elseif action_id == hash("w") then
self.i.y = self.speed
elseif action_id == hash("s") then
self.i.y = -self.speed
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
print("Collide!")
if message.own_group == hash("danger") then
self.i = self.i - (self.i * 2)
end
end
end
Edit: I’m asking for a way to stop movement when hitting an object, not a way to allow collisions to happen. Top-down btw.