Fire bullet in actors direction
Macca_McGill
Member, PRO Posts: 108
Hi,
I've got an actor in the centre of the screen that rotates to mouse position which works fine. It spawns a bullet behind this actor that fires but it's firing in the wrong direction. So for example if the ship is pointing directly up, the bullet is firing 90 degrees off to the right. I'm using the vector to angle on the ship as per below:
VectorToAngle(game.mouse.position.x - self.position.x,game.mouse.position.y - self.position.y)
I've tried adding +90 and -90 at the end but then that means the bullet fires at the same angle but the bullet is rotated as it is using a change velocity on the bullet set to 0.
I know this is probably a noob question and i've searched the forums/examples/demo's but to no avail yet.
Thanks
Comments
In the spaw behavior, set the direction to self.rotation.
Mental Donkey Games
Website - Facebook - Twitter
Thanks for the reply. It's still a bit funny with where they are firing as per the image below.
https://dropbox.com/s/nz4s2fj48uv8u27/Capture.PNG?dl=0
This doesn't tell us anything in that without knowing the orientation of your image asset 'pointing directly up' could mean anything, it doesn't tell us in which direction the actor is pointing.
An image of a gun pointing to the right - applied to an actor and set so that it is pointing up - will mean the actor is rotated by +90 degrees.
An image of a gun pointing upwards - applied to an actor and set so that it is pointing up - will mean the actor is at 0 degrees.
. . . etc etc
Hi Socks,
I've just dragged the actor directly onto the scene and not changed its orientation at all. I'm guessing by default they point to 0? But the image itself would be pointing at 90 as its facing upwards.
Would it best to spawn the actor on screen and have it facing to 90 rather than drag the actor onto the scene then so they are both pointing in the same direction?
Thanks
Always.
It'll cause you some degree of confusion having your image oriented at an angle other than 0 degrees, so while your image is pointed at 90 degrees your actor's rotation will read 0 degrees, and when you spawn an actor (for example a bullet) it will appear to come from the side (0 degrees) rather than from the top . . . personally I'd just use one orientation for both actors and images rather than having two different angles, that's not to say you can't work like that, but the additional need for offsets and keeping on top of the conflicting angles is unecessry extra work.
Think of it like this, you have set of numbers (sepetate images) for a custom font, but their values are offset by 3, so the image for 1 is called ’4', the image for 2 is called '5' (and so on), you can of course work like this, but it requires extra work, a little extra maths every time you employ the font and a little extra thought from you to avoid making mistakes . . . but why not just rename the image with names that match their values, which would remove the extra code work and avoid confusion, I'd do the same with spaceship images, make the ship point at 0 degrees rather than import it with a built in angle offset.
Both ? I don't understand ? Whether you spawn an actor or drag an actor into scene has no effect on the orientation, a dragged actor can be set to any angle you like, a spawned actor can be spawned at any angle you like.
I rotated the image and re-imported it so that it's orientation is at 0 along with the bullet. Re-opened the project and it's working OK now. I'm guessing I confused myself by having them at different angles.
Thanks for the info