Having issue with how bullets are generating when my player rotates

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.
Post Reply
Teshi
Prole
Posts: 11
Joined: Mon Feb 01, 2016 6:51 pm

Having issue with how bullets are generating when my player rotates

Post by Teshi »

Hi, im new to game programming but im having a go with a top down shooter. A found an open source sprite online and ive got it to rotate based on where the mouse is but now ive hit a bit of a wall in getting the bullets to rotate their starting position too, im not too sure how to go about it. Thanks for any help!
Game.love
WIP
(13.02 MiB) Downloaded 179 times
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Re: Having issue with how bullets are generating when my player rotates

Post by rougan »

I guess you could get the gradient of the line between the center of your player and the position of the cursor. Once you know that gradient, you can just move your bullet along that line until it reaches it's target. Using the same rotation amount for the bullet should keep it pointing in the same direction as your player (I hope) :nyu:
Teshi
Prole
Posts: 11
Joined: Mon Feb 01, 2016 6:51 pm

Re: Having issue with how bullets are generating when my player rotates

Post by Teshi »

I think i phrased my issue wrongly, basically i can get bullets to fire towards the cursor but I dont know how to make it look like its coming out of the gun in the sprite basically
User avatar
farzher
Prole
Posts: 42
Joined: Fri Jul 31, 2015 5:38 pm

Re: Having issue with how bullets are generating when my player rotates

Post by farzher »

Teshi wrote:im not too sure how to go about it.
Here's the math

Code: Select all

xoffset = 50
yoffset = 10

bulletx = player.x + math.cos(player.angle)*xoffset + math.cos(player.angle+math.pi/2)*yoffset
bullety = player.y + math.sin(player.angle)*xoffset + math.sin(player.angle+math.pi/2)*yoffset
Understanding math is pretty important, I recommend looking up why this works (at least I think it works)
Otherwise you'll get stuck again and again
butts
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests