there is probably an easy solution of that, but i can't find it.
The problem is that i have set the camera to look at the player and the player to look at the mouse, but
mouse X and the mouse Y are not updating properly
DEMO:
problem with the camera, player not being able to look at the mouse
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: problem with the camera, player not being able to look at the mouse
The main problem is you weren't taking the player position and camera translation into account. The below in the draw method your player class draws the player facing left or right and a small square from the centre of the player in the direction of the mouse.
Code: Select all
local mx = (love.mouse.getX() + self.x - (love.graphics.getWidth()/2))
local my = (love.mouse.getY() + self.y - (love.graphics.getHeight()/2))
local dx = mx - self.x
local dy = my - self.y
local dist = math.sqrt(dx*dx + dy*dy)
local normdx = dx/dist
local normdy = dy/dist
if dx >= 0 then
love.graphics.draw(self.playerRight,self.x,self.y,0,1,1,32,60)
else
love.graphics.draw(self.playerLeft,self.x,self.y,0,1,1,32,60)
end
love.graphics.rectangle("fill", self.x + normdx * 96 - 2, self.y + normdy * 96 - 2, 4, 4)
Who is online
Users browsing this forum: No registered users and 2 guests