So far my little test game has gone well, and the floor detection is okay, but I’m trying to figure out how to detect ceilings / roofs and move the opposite direction. Is there a way I could detect like, the specific side of a collision object I’m detecting? (btw kinematic)
Code for my movement:
function init(self)
msg.post(".", "acquire_input_focus")
self.startPos = vmath.vector3(640, 360, 0)
go.set_position(self.startPos)
self.i = vmath.vector3()
self.VelocityY = -1
self.jumpLimit = 1
fall = true
jumping = 0
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
self.p = go.get_position()
self.p.y = self.p.y + (math.abs(self.VelocityY) * 1.25)
if jumping > 0 then
self.VelocityY = self.VelocityY + 5
self.VelocityY = self.VelocityY * -1
else
self.VelocityY = .25
end
jumping = 0
end
end
function update(self, dt)
self.p = go.get_position()
self.p = self.p + self.i
self.p.y = self.p.y + self.VelocityY
if fall == true then
if self.VelocityY > -48 then
self.VelocityY = self.VelocityY - .5
end
end
go.set_position(self.p)
self.i = vmath.vector3()
end
function on_input(self, action_id, action)
if action_id == hash("up") then
if action.pressed and jumping < self.jumpLimit then
self.VelocityY = 15
jumping = jumping + 1
end
elseif action_id == hash("left") then
self.i.x = -5
elseif action_id == hash("right") then
self.i.x = 5
end
end