Why is this collision not working?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
lilfinn
Prole
Posts: 10
Joined: Thu Jul 18, 2013 5:58 am

Why is this collision not working?

Post by lilfinn »

I'll let the code speak for itself but I can't seem to understand why the player doesn't stop when colliding with the ground?

Thanks in advance!
Attachments
RCC.zip
(6.2 KiB) Downloaded 119 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Why is this collision not working?

Post by micha »

In the players update replace this:

Code: Select all

for i,v in ipairs(node) do
  if CheckCollision(Player.x,Player.y,Player.width,Player.height, v.x,v.y,2,1) then
    Player.onGround = true
  else 
    Player.onGround = false
  end
end
by this:

Code: Select all

Player.onGround = false
for i,v in ipairs(node) do
  if CheckCollision(Player.x,Player.y,Player.width,Player.height, v.x,v.y,2,1) then
    Player.onGround = true
  end
end
If there are several nodes and the player collides with node 1 but not with node 2, then your code sets the onGround to false (because node 2 is checked after node 1). But you want to detect a collision if the player collides with any node.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests