Page 1 of 1

Question and help: Angles, Bitmap and Player Position

Posted: 15 Jun 2020, 0:34
by Victor ManuelMR
Well, I'm working with bitmap, but I don't have much idea of how it works exactly.
For example: I'm making a Bullet Bill Launcher that changes angles, depending on the player's position.
Bitmap Help.png

Bitmap(1).rotatang is very confusing, (even if its function is already rotating) I don't know how I could use it to change angles depending on the player's location (x, y)...
npc-233.png
npc-233.png (690 Bytes) Viewed 1031 times

Posted: 16 Jun 2020, 1:30
by HugoMDM
Rotatang works on radians

Pi = 180 degress
Pi/2 = 90 degress
Pi*2 = 360 degress

Posted: 16 Jun 2020, 5:26
by Victor ManuelMR
Spoiler
Victor ManuelMR wrote:Well, I'm working with bitmap, but I don't have much idea of how it works exactly.
For example: I'm making a Bullet Bill Launcher that changes angles, depending on the player's position.
Bitmap Help.png

Bitmap(1).rotatang is very confusing, (even if its function is already rotating) I don't know how I could use it to change angles depending on the player's location (x, y)...
npc-233.png

Find a way (Thanks to Monad): and everyone who helped in the post

Code: Select all

bitmap(1).rotatang = angle(.x - char(1).x, char(1).y - .y) + pi/2


IN DEGREES by SetaYoshi

Code: Select all

script angle(width as double, height as double, return double)
 return 2*pi*getangle(param(width), param(height))

Posted: 20 Jun 2020, 2:12
by Monad
Actually the mathematically accurate way to do this is the following:

Code: Select all

do

with bitmap(1)
   .rotatang = atan2(.desty + 0.5 * .scrheight - (char(1).y + 0.5 * char(1).pheight), .destx + 0.5 * .scrwidth - (char(1).x + 0.5 * char(1).pwidth))
end with

call sleep(1)
loop

script atan2(y as double, x as double, return double)
   return 2 * pi * getangle(y, x)
end

Note that in the example I'm using a bitmap, so you if use an NPC instead you will have to do some adaptations, but the logic keeps the same.