rotate an image in the direction of the mouse

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.
Heeloo
Prole
Posts: 3
Joined: Mon Jun 23, 2014 6:52 am

Re: rotate an image in the direction of the mouse

Post by Heeloo »

I have edited but I am getting the same error.

Code: Select all

local zombo = require "zombo"
local man = require "man"

function love.load()
	man.load()
	zombo.load()
end



function love.update(dt)
	findRotation = math.atan2(mouseY - many, mX - manx)
	man.update()
	mouseY = love.mouse.getY()
end

function love.keypressed(key)
	if key == "escape" then
		love.event.quit()
	end

end

function love.draw()
	man.draw()
	zombo.draw()
end
the error I get is

main.lua:12: attempt to perform arithmetic on global 'mouse Y' (a nil value)
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: rotate an image in the direction of the mouse

Post by Plu »

During the very first frame, you only load the mouseY variable after trying to use it. You need to either move up the line where you set the mouseY, or you need to initialize it with some kind of default value. (I think in this case it should be the former)
Post Reply

Who is online

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