I have a rotating player that is always facing the mouse, the player shoots when they click.
I want the bullet to go in the direction of wherever the mouse was when it was clicked, and after searching for it a few times on the forums, I can't find a solid answer. Can someone help me out?
Bullets with rotating player[SOLVED]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- baconhawka7x
- Party member
- Posts: 484
- Joined: Mon Nov 21, 2011 7:05 am
- Contact:
Bullets with rotating player[SOLVED]
Last edited by baconhawka7x on Wed Aug 21, 2013 4:48 am, edited 1 time in total.
Re: Bullets with rotating player
Allow me to quote myself here
Code: Select all
function love.load()
bullets = {}
bullet_speed = 200
end
function love.update(dt)
for i,v in ipairs(bullets) do
v.x = v.x + math.cos(v.a) * bullet_speed * dt
v.y = v.y + math.sin(v.a) * bullet_speed * dt
end
end
function love.mousepressed(x, y, k)
if k == "l" then
bullets[#bullets + 1] = {
x = player.x,
y = player.y,
a = getAngle(player.x, player.y, x, y) --Angle between player and mouse
}
end
end
end
function getAngle(x1, y1, x2, y2)
return math.atan2(x2-x1, y2-y1)
endRe: Bullets with rotating player
Check out this little game I made to test just that. Just warning you: the game only functions in the sense of shooting and moving, not the bullet hitting the player.
- Attachments
-
gunner.love- (54.24 KiB) Downloaded 162 times
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- baconhawka7x
- Party member
- Posts: 484
- Joined: Mon Nov 21, 2011 7:05 am
- Contact:
Re: Bullets with rotating player
Yuss! Thank you, I got it figured out. A lot of the issues I was having were with an obvious issue that slipped my mind. I am zooming in the camera, which tends to complicate things. But It's all figured out now:Ddavisdude wrote:Check out this little game I made to test just that. Just warning you: the game only functions in the sense of shooting and moving, not the bullet hitting the player.
Re: Bullets with rotating player[SOLVED]
Scaling ALWAYS seems to mess things up for me. No problem!
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: No registered users and 18 guests