Help with AT Collider

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
User avatar
ac3raven
Citizen
Posts: 60
Joined: Tue May 19, 2009 1:14 am

Help with AT Collider

Post by ac3raven »

I have been wrestling with getting AT collider to work for the past few days and even after re-writing my game from scratch, I can't get it to do anything. I'm working on a top-down shooter and have gotten ATL to load a tmx file with certain tiles being set with an "obstacle" property, but I can't get ATC to do anything.

My current code should theoretically stop the player from moving downward in the y-direction when the bottom sensor collides with a tile of the "obstacle" property:

Code: Select all

map_width = 1440
map_height = 2160

require "camera"


function map_load()
	--ATL STUFF
	loader = require("atl.loader")
	loader.path = "maps/"
	map = loader.load("example.tmx")
	tx = 0
	ty = 0
	scale = 1
	map:setDrawRange(0,0,map_width,map_height)
	
	--ATC STUFF
	entity = require "atc.atc"
	player = {}
		player.x = 48
		player.y = 48
		player.xvel = 0
		player.yvel = 0
		player.speed = 50
		player.friction = 3.5
		player.object  = entity.new(player.x,player.y,20,20,map,terrain)
		player.pic = love.graphics.newImage("images/tile0.png")
		
	function player.object:isResolvable(side,tile,gx,gy)
		local tp = tile.properties
		
		if tp.type == "obstacle" then
			if side == "bottom" then player.y = 0 end
			return true
		end
	end
		
		
		
		
		
end

function map_update(dt)
	--for player mouse look
	mousex, mousey = camera:mousePosition()

	player.x = player.x + player.xvel
	player.y = player.y + player.yvel

	player.xvel = player.xvel * (1-math.min(dt*player.friction,1))
	player.yvel = player.yvel * (1-math.min(dt*player.friction,1))
	
	--Player Moving
	if love.keyboard.isDown("d") and 
	player.xvel < 100 then
		player.xvel = player.xvel + player.speed * dt	
	end

	if love.keyboard.isDown("a") and 
	player.xvel > - 100 then
		player.xvel = player.xvel - player.speed * dt	
	end
	
	if love.keyboard.isDown("w") and 
	player.yvel > - 100 then
		player.yvel = player.yvel - player.speed * dt	
	end
	
	if love.keyboard.isDown("s") and 
	player.yvel < 100 then
		player.yvel = player.yvel + player.speed * dt	
	end
	
	--atc function
	player.object:move(player.xvel,player.yvel)
	
end

function map_draw()
	local ftx, fty = math.floor(tx), math.floor(ty)
	love.graphics.push()
	love.graphics.scale(scale)
	love.graphics.translate(ftx,fty)
	map:draw()
	love.graphics.pop()
	
	--player drawing
	local rot = math.atan2(mousey - player.y, mousex - player.x)
	love.graphics.draw(player.pic,player.x,player.y,rot,1,1,player.pic:getWidth()/2,player.pic:getHeight()/2)
	player.object:draw("fill")
	
	
	
end
But nothing happens as far as collision is concerned. Attached is my .love file.

Thanks.
Attachments
shootstuff6.love
(227.84 KiB) Downloaded 72 times
User avatar
markgo
Party member
Posts: 190
Joined: Sat Jan 05, 2013 12:21 am
Location: USA

Re: Help with AT Collider

Post by markgo »

Hi there. In ATL, properties are stored as key-value pairs. In your case, your key is named "obstacle" paired up with the empty string "". You should be checking for tile.properties.obstacle. If you're making a one way platform, it's probably good to do an additional check on your velocity as well to prevent the obstacle from pushing the object up when moving up, left, or right.

Code: Select all

       function player.object:isResolvable(side,tile,gx,gy)
          local tp = tile.properties
          
          if tp.obstacle then
             if side == "bottom" then 
               return true
               player.y = 0 
              end
          end
       end
Post Reply

Who is online

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