Question and help: Angles, Bitmap and Player Position

Description: Internal scripting system of SMBX-38A Engine based on the simple VB-like language
Moderators: Yoshi021, 5438A38A, Moderators, Semi-moderatos

VictorMR M
Topic author, Count
Count
Avatar
VictorMR M
Topic author, Count
Count
Age: 24
Reputation: 165
Posts: 242
Joined: 7 Feb 2018

Post #1by VictorMR » 15 Jun 2020, 0:34

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 4627 times
Last edited by VictorMR on 21 Oct 2020, 19:55, edited 2 times in total.
Image
[1.4.5] - Dream Team at The Challenging Portals:
Image

HugoMDM M
Our friend
Our friend
Avatar
HugoMDM M
Our friend
Our friend
Age: 25
Reputation: 71
Posts: 79
Joined: 17 Apr 2016
YouTube Youtube channel URL

Post #2by HugoMDM » 16 Jun 2020, 1:30

Rotatang works on radians

Pi = 180 degress
Pi/2 = 90 degress
Pi*2 = 360 degress
I make good scripts for everyone c:
Scripting YT channel
https://www.youtube.com/channel/UChaWgDsfMCqJzeV0bmDs-Mw?view_as=subscriber

VictorMR M
Topic author, Count
Count
Avatar
VictorMR M
Topic author, Count
Count
Age: 24
Reputation: 165
Posts: 242
Joined: 7 Feb 2018

Post #3by VictorMR » 16 Jun 2020, 5:26

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))
Image
[1.4.5] - Dream Team at The Challenging Portals:
Image

Monad
Passerby
Passerby
Monad
Passerby
Passerby
Reputation: 2
Posts: 2
Joined: 26 Apr 2020

Post #4by Monad » 20 Jun 2020, 2:12

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.

hiyaragi M
Nice citizen
Nice citizen
Avatar
hiyaragi M
Nice citizen
Nice citizen
Age: 21
Reputation: 1
Posts: 11
Joined: 4 Dec 2024
English Pronouns: It/He/O
Location: Turkey

Post #5by hiyaragi » 20 Jul 2026, 22:17

VictorMR 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
i searched and found the solution:

Code: Select all

Call BmpCreate(an unique bitmap ID for your bitmap, NPC graphic ID for your bitmap(just uses first frame :( ), 0, 1, 0, 0, your bitmap's width, your bitmap's height, .x, .y, 1, 1, your bitmap's rotation point's x, your bitmap's rotation point's y, 0, -1)
.forecolor = RGBA(255,255,255,0)
bitmap(bitmap ID what you wrote).rotatang = getangle(.y - char(1).y, .x - char(1).x) * (pi * 2)

HengShao M
Moderator
Moderator
Avatar
HengShao M
Moderator
Moderator
Age: 25
Reputation: 86
Posts: 87
Joined: 8 Jan 2016
Tencent QQ

Post #6by HengShao » 22 Jul 2026, 11:17

hiyaragi wrote:
VictorMR 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
i searched and found the solution:

Code: Select all

Call BmpCreate(an unique bitmap ID for your bitmap, NPC graphic ID for your bitmap(just uses first frame :( ), 0, 1, 0, 0, your bitmap's width, your bitmap's height, .x, .y, 1, 1, your bitmap's rotation point's x, your bitmap's rotation point's y, 0, -1)
.forecolor = RGBA(255,255,255,0)
bitmap(bitmap ID what you wrote).rotatang = getangle(.y - char(1).y, .x - char(1).x) * (pi * 2)
Please check the date this thread was posted before replying.
2333~ :huaji:
A SMBX-38A project I am working on:
Image

If you're interested in the project above, or just want to discuss SMBX, welcome to the Hel Studio Discord Server~ :
https://discord.gg/YS6bfysduC

hiyaragi M
Nice citizen
Nice citizen
Avatar
hiyaragi M
Nice citizen
Nice citizen
Age: 21
Reputation: 1
Posts: 11
Joined: 4 Dec 2024
English Pronouns: It/He/O
Location: Turkey

Post #7by hiyaragi » 5 Sep 2026, 21:18

Thank all of you for help, thanks to all of you, i made this: https://drive.google.com/file/d/1-pshTeqh0chxq-PMdIlPxjMHerjq23J9/view?usp=sharing. but it can be a little glitchy. :beta:

and i musn't forget to say: sprite by master darkar, not me.


Return to “TeaScript”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest