How can I spawn bullets at a weapons barrel [SOLVED]

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
Darton
Prole
Posts: 3
Joined: Tue Aug 24, 2021 2:28 pm
Location: Canada

How can I spawn bullets at a weapons barrel [SOLVED]

Post by Darton »

First time posting so apologies if I mess anything up.
Picture
Picture
picture.PNG (2.17 KiB) Viewed 2136 times
The highlighted green part is where the gun is attached to the player, it rotates around this point using:

Code: Select all

math.atan2(y2-y1,x2-x1)
This is all great however when I create a bullet I want to to be where the pink is. Now normally I would have x and y offset variables to do this for me but since the gun is rotating It will not work. Now I have tried to multiple the guns x and y with math.cos/sin with the guns angle but the I have not been able to get it to work. I have been stuck with this problem for a while and its probably due to my lack of understanding with basic trig; so any help or advice is appreciated :3
weapon.lua
(2.79 KiB) Downloaded 70 times
Last edited by Darton on Thu Aug 25, 2022 2:34 pm, edited 1 time in total.
User avatar
knorke
Party member
Posts: 274
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: How can I spawn bullets at a weapons barrel

Post by knorke »

Welcome.
Now I have tried to multiple the guns x and y with math.cos/sin with the guns angle but the I have not been able to get it to work
That is the correct approach.
Should be something like:

Code: Select all

pink.x = green.x + cos(gunAngle) * gunLength
pink.y = green.y + sin(gunAngle) * gunLength
(depending how the coordinates system is set up etc)
It is easier when you attach the whole project so that we can actually run and test it.
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: How can I spawn bullets at a weapons barrel

Post by togFox »

Remember love uses radians by default - not degrees.

0 radians is "right" or "east" or 90 degrees or positive x axis or 3 o'clock! and it goes clockwise.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Darton
Prole
Posts: 3
Joined: Tue Aug 24, 2021 2:28 pm
Location: Canada

Re: How can I spawn bullets at a weapons barrel

Post by Darton »

knorke wrote: Thu Aug 25, 2022 5:02 am Welcome.
Now I have tried to multiple the guns x and y with math.cos/sin with the guns angle but the I have not been able to get it to work
That is the correct approach.
Should be something like:

Code: Select all

pink.x = green.x + cos(gunAngle) * gunLength
pink.y = green.y + sin(gunAngle) * gunLength
(depending how the coordinates system is set up etc)
It is easier when you attach the whole project so that we can actually run and test it.
Seems to have worked. Thanks :D
Darton
Prole
Posts: 3
Joined: Tue Aug 24, 2021 2:28 pm
Location: Canada

Re: How can I spawn bullets at a weapons barrel

Post by Darton »

togFox wrote: Thu Aug 25, 2022 12:06 pm Remember love uses radians by default - not degrees.

0 radians is "right" or "east" or 90 degrees or positive x axis or 3 o'clock! and it goes clockwise.
Thanks good to know, thanks TogFox :D
Post Reply

Who is online

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