[solved]Collision response: the right direction

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
Posts: 2
Joined: Tue Aug 14, 2018 12:03 pm

[solved]Collision response: the right direction

Post by M3G0 » Tue Aug 14, 2018 12:33 pm


I'm new to this forum and I recently picked up Lua and Love2D. After a few tutorials, I started to feel confident and make my very first game.

Currently I have been making a AABB collision and response program that will correct the player depending on the moving object direction.

Code: Select all

function collisions:update()
	-- checks for every object on scene
	for i = 1,#colliders do
		--checks for every tile (solid) on scene
		for j = 1,#platforms do
			object = colliders[i]
			platform = platforms[j]
			collision = ( object.x + object.width > platform.x and object.x < platform.x + platform.width and object.y + object.height > platform.y and object.y < platform.y + platform.height)
			if collision == true then
				print ("hey")
				if object.dirX > 0 then 
				object.x = platform.x - object.width -1
				if object.dirX < 0 then 
				object.x = platform.x + platform.width +1
				print ("l")
				if object.dirY < 0 then 
				object.y = platform.y + platform.height +1
				print ("u")
				if object.dirY > 0 then 
				object.y = platform.y - object.height -1
				print ("d")
The problem however is that as seen on the attachment. The blue box (moving object) is attempting to collide with the static black box. Because it is moving diagonally, it sets the variables dirX and dirY to be true thus sending the blue box to the orange position rather than the desired yellow position. Any ideas how to fix this?

Edit 10/12/2018:
I simply tagged objects if they are in the x axis of moving object or y axis of moving object
Pic.png (7.08 KiB) Viewed 244 times

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests