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.