Body collision test (Solved)

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
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Body collision test (Solved)

Post by Taehl »

How can I tell when two Bodies are colliding? I've made a little physics-enabled platformer game, but I want to prevent players from jumping in midair.

Thanks in advance for any assistance. I'm new to LOVE, but I'm fairly skilled with Lua.
Last edited by Taehl on Sat Jan 16, 2010 12:04 pm, edited 1 time in total.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Body collision test

Post by bartbes »

You could create a variable, say canjump, and set that to true in the collision add callback, and false in the collision remove callback. (see this doc page)
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Body collision test

Post by Taehl »

EDIT) Aah, I hacked something out. Thank you!

Code: Select all

world:setCallbacks(
	nil,
	-- While things are colliding
	function(shape1, shape2, contact)
		if shape1 == "playerbottom" or shape2 == "playerbottom" then
			player.bottomtouch = true
		end
		if shape1 == "playertop" or shape2 == "playertop" then
			player.toptouch = true
		end
	end,
	-- When things stop colliding
	function(shape1, shape2, contact)
		if shape1 == "playerbottom" or shape2 == "playerbottom" then
			player.bottomtouch = false
		end
		if shape1 == "playertop" or shape2 == "playertop" then
			player.toptouch = false
		end
	end,
	nil
)
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 54 guests