Help with camera issues.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
thyrgle
Prole
Posts: 10
Joined: Wed Jun 26, 2013 6:30 pm

Help with camera issues.

Post by thyrgle »

Hi, I am trying to figure out how to use this module: http://nova-fusion.com/2011/04/19/camer ... he-basics/. I have two balls. One ball is called "player" the other is called "enemy". I want my camera to be focused on the midpoint between the two balls. Next, I want the camera to zoom out enough, so that both balls can be seen (with the addition of some padding). This effect, I believe, is similar to Super Smash Bros. I have tried this:

Code: Select all

function updateCamera()
	--Useful legibility vars.
	local p_x = player.body:getX()
	local p_y = player.body:getY()
	local e_x = enemy.body:getX()
	local e_y = enemy.body:getY()

	--Zoom it out based on distance.
	local x = p_x - e_x
	local y = p_y - e_y
	local dist = math.sqrt(x*x + y*y) --Distance formula
	local pad = 0.45
	local scale = math.log(math.abs(dist))*pad --Yeah, this worked best so far, I don't know why...
	camera:setScale(scale,scale)

	--Make camera look at the center between the two balls.
	local mid_point_x = (p_x + e_x)/2 --Midpoint formula
	local mid_point_y = (p_y + p_x)/2
	local offset_x = W/2*scale --Take into account the love2d coordinate system with the offsets
	local offset_y = H/2*scale
	camera:setPosition(mid_point_x-offset_x, mid_point_y-offset_y)
end
My original updateCamera function, which is called in the love.update function, had simply used dist*pad instead of log(abs(dist))*pad, but for some reason, the camera seems to move better with the log (not perfectly though, sometimes a ball will go out of the visibility range, and I also don't know why it works better). Is there a way to fix my updateCamera function so it produces a Super Smash Bros like camera effect?

Thanks.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Help with camera issues.

Post by jjmafiae »

post this in support and development instead :ultraglee:
thyrgle
Prole
Posts: 10
Joined: Wed Jun 26, 2013 6:30 pm

Re: Help with camera issues.

Post by thyrgle »

Ok thanks, sorry about that. Here is the new place: viewtopic.php?f=4&t=37923
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests