Let’s say I have an enemy at position ( 150, 150 ) in my screen and I want it to shoot a bullet from its position at an angle of 315° (south-east if we’re cosidering a regular unit circle)…
I’ve tried doing something like this (pseudo-code):
bullet.xpos = enemy.xpos + (cos(315) * bullet.radius )
bullet.ypos = enemy.ypos + (sin(315) * bullet.radius )
The idea is to change the bullet’s position by increasing its radius…
However, the problem with this code is that the angle at wich the bullet gets placed it’s not really the one specified (315° in this case) because of course, the final result going into the bullets position gets influenced by the enemy’s position ( bullet.xpos = enemy.xpos… and bullet.ypos = enemy.ypos… ) but I still need to consider it since it will be the starting point for the bullet.
I might be overlooking something but I’m not sure how to actually do this… Thanks for taking the time