the player object is not colliding with the Black border, or any other elements. I have looked at the example project.
I have also handled a collision as seen below. this is in my player script
local CONTACT_POINT_RESPONSE = hash("contact_point_response")
local BORDER = hash("border")
function init(self)
msg.post(".","acquire_input_focus")
msg.post("@render", "use_camera_projection")
camera.acquire_focus("operatorMap#cameramap")
self.correction = vmath.vector3(0, 0, 0)
self.vel = vmath.vector3(0, 0, 0) -- Initialize velocity
end
local function flip(direction)
sprite.set_hflip("#sprite", direction < 0) --flips sprite horizontally, first file, 2nd true false if they Should be flipped
end
local function play_animation(self, newAnimation)
if self.animation ~= newAnimation then
sprite.play_flipbook("#sprite", newAnimation) --first is file that controls it, second is name of animation
self.animation = newAnimation
end
end
local function animate(self)
if self.groundContact then
if self.velocity == 0 then
play_animation(self, "IdleMap")
else
play_animation(self, "IdleMap") --idle is stand in for movement animation
end
else
play_animation(self, "IdleMap") -- idle is stand in for jumping animation
end
end
function update(self, dt)
local pos = go.get_position() -- Get current position
pos = pos + self.vel * dt -- Update position based on velocity
go.set_position(pos) -- Set new position
self.vel.x = 0 -- Reset velocity
self.vel.y = 0
--reset correction
self.correction = vmath.vector3()
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.vel.y = BASEVELOCITY -- Move up
elseif action_id == hash("down") then
self.vel.y = -BASEVELOCITY -- Move down
elseif action_id == hash("left") then
self.vel.x = -BASEVELOCITY -- Move left
elseif action_id == hash("right") then
self.vel.x = BASEVELOCITY -- Move right
elseif action_id == hash("esc") and action.released then
msg.post("menu#PauseMenu", "enable")
end
end
local function handleLevelCollisions(self, normal, distance)
if normal == nil then
print("Error: normal is nil")
return
end
print("Collision Normal:", normal)
-- Get the info needed to move out of collision. We might
-- get several contact points back and have to calculate
-- how to move out of all of them by accumulating a
-- correction vector for this frame:
if distance > 0 then
-- First, project the accumulated correction onto
-- the penetration vector
local proj = vmath.project(self.correction, normal * distance)
if proj < 1 then
-- Only care for projections that does not overshoot.
local comp = (distance - distance * proj) * normal
-- Apply compensation
go.set_position(go.get_position() + comp)
-- Accumulate correction done
self.correction = self.correction + comp
end
end
end
function on_message(self, message_id, message, sender)
if message_id == CONTACT_POINT_RESPONSE then
if message.group == BORDER then
handleLevelCollisions(self, message.normal, message.distance)
end
end
if message_id == hash("startRecievingInput") then
recievingInputs = true
print("restarting inputs")
end
if message_id == hash("stopRecievingInput") then
recievingInputs = false --this isn't connecting properlt eith itself in this script
print("Stopping all inputs")
end
end