Need to test the angle of the cursor (or an object) in relation to player for a 2D platformer


#22

Hi again!

First of all, Huge thanks for all the help so far and sorry for delay to reply again! Hard to get back to building this game. much the less trying to fix issues with it… :sweat_smile:

So… the game is now working the aim almost perfectly, but… the very neutral-forward aim angles (Where 359 and 0 degrees meet) aren’t being detected at all by the game. I have no idea why and I tried several tweaks to fix it… but nothing worked. it simply won’t detect that angle range and I have no clue why. but I assume it’s related to the fact that, for some reason, it doesn’t seem to be properly rounded…?

Both 360 and 0 degrees appear when aiming around that angle… shouldn’t it jump from 359 straight back to 0…?

Anyway… the build online is once again updated in case you want to check it for yourself… and here’s the screenshots too.

Please help… idk what else to do and everything else so far seems to be working perfectly…


#23

why do you not just use the setup from my fixed example?
there the angle detection works. you only need to make 16 sprites for each angle.
flipping and changing angle is not needed.
I thought that was the whole point of having the angles in the first place.


#24

1 - My setup was done using yours. sans for the lack of detecting the front angle, they share the same issues. :slightly_smiling_face:

Feel free to open yours and see for yourself, yours also goes to 360 before reaching zero. and its “turning point” between 360 and 0 degrees changes if you’re moving the mouse up from a higher angle, or down from a lower one.

2 - I don’t want people to make me a game. I want to learn to make a game myself. so I prefer making my own methods based on what I learn rather than frankensteining a bunch of copy-pastes of others without knowing and understanding what it does

3 - The angles are unchanged, and the flipping was done solely to save sprites (Since half of them are technically the same picture, just flipped anyway, I just made the program flip the image itself instead. which saves space and time.) I also diminished the number of angles atm to 8 because I’m still learning and trying to get the hang of this. but I’ll go back to 16 once I can manage to get it fully working :slightly_smiling_face:


#25

E. ah i see, when shooting straight forward and you where shooting up before the sprite shows the 16th frame.
if you want to fix that 360to0 just use 359 value instead of 360 in the formula.

and in the screenshot you refer to a global variable again. there is absolutely zero reason to make the angle global available. otherwise that should work as intended. what exactly is the problem in your screenshot setup?
also your file is down


#26

@Archezuli, I realise I’ve jumped into the converasation a bit late, but I think there may be a much easier way to achieve what you’re after without the use of trigonometry:

  • Rotate your player towards the mouse pointer is using the Player’s action “Rotate Toward Position”
  • The get the angle of the player with Player.Angle()
  • Use that angle to determine the sprite to display.

If you do it right, you can set each animation so that it matches the angle divided by 22.5 (360 degrees in 16 parts). The all you need to do is rotate the player, and set the animation number = round(angle/22.5).

2, possibly 3, lines of code. Quick and simple.


#27

Okay, first things first…

IDK Why Dropbox says file is deleted. I’ll leave a link to the folder instead to circunvent this. let’s hope it’ll be enough…

Now,

The angle detection is fixed. turns out it was a logical issue.

The program needed to check for either variable to be true, not both… took me a bit to realize that, but the fix was easy peasy cuz I already knew how to add that.

With that out of the way, a few things still stand of my way of a clean start.

First of all,

By far the one thing that’s bugging me the most atm. the angle at 0… is not straightforward.

Ironically, however… 180 seems to be working just fine?

Feel free to check it out yourselves on the file. it’s much better to see how inclined the angle 0 is than in the screenshot.

Secondly…

image

Pixels are clearly not scaling properly… I’m not sure how to fix that…

And lastly,

image

Blurry text… how can I make it scale proportionally and with no antialiasing?

@Archezuli, I realise I’ve jumped into the converasation a bit late, but I think there may be a much easier way to achieve what you’re after without the use of trigonometry:

Rotate your player towards the mouse pointer is using the Player’s action “Rotate Toward Position”
The get the angle of the player with Player.Angle()
Use that angle to determine the sprite to display.

If you do it right, you can set each animation so that it matches the angle divided by 22.5 (360 degrees in 16 parts). The all you need to do is rotate the player, and set the animation number = round(angle/22.5).

2, possibly 3, lines of code. Quick and simple.

@MrMen Thank you for this! Brilliant idea!

I thought of something similar myself, but I thought in my head it wouldn’t work out because of the sprite constantly flipping between the rotated and non-rotated state… and admittedly didn’t try… so thank you! I have added it to the programming with full success.

I’m still gonna add the second part (Using the angle to tell which sprite the game should display, as slash suggested before.), but I still want to fix those aforementioned issues before that. Hopefully you guys can still help me out? :slightly_smiling_face:


#28

I think the reason your shooting beam is slightly skewed is because of the origin point of your cursor isn’t in dead center, but rather in the top left like a traditional arrow cursor. I don’t know if there’s a way you can change the origin point of the new mouse cursor; I’m completely unfamiliar with that extension: I’ve never needed it.

I changed it to this, and the beam fires straight, but appears to be firing directly above the mouse cursor (aiming to the top left corner)


#29

@fitkoh Well… that kinda seemed to be the problem…? ‘-’

Thanks. it’s much better now!

However, as you can see… the lasers are emitting that odd “fallen” rear trailing near the ends of the screen, despite going seemingly straight now… I wonder if this is related to the screen not scaling properly…?

Edit:

image

I tried with the screen unscaled and… now there’s a laser in the middle seemingly slightly twisted|rotated…?

Oh man… I’m gonna go crazy with this… :sweat_smile:


#30

It’s possibly an optical illusion. When I look at the screen shot the lazers appear to be wobbling… and it’s definitely a static image (the unscaled screenshot)


#31

It’s not an optical illusion, it’s right there

image

Here’s an upscaled version of that snip, in case you’re not good at viewing tiny pictures

image


#32

Yeah it’s more apparent in the enlarged snip. I admire your attention to detail, to want to refine something I probably never would have noticed in the first place.

This is just a shot in the dark, I really have no idea if it will work or not… but if you view your game properties (Project Manager -> Game Settings -> Game Properties), there’s an option for “Scale Mode” which you can select “Antialiasing” or “Nearest.”

It recommends “Nearest” for “Pixel Perfect” games, and to disable “smoothing” in the resource editor for all images. Maybe it’s worth trying?


#33

Yeah… I set it to nearest before I even started actually making the game… as for the resource editor… I found no such options anywhere. so no idea how to do so.


#34

The resource editor is located at Project Manager -> Game Settings -> Resources.

From there you can click on an object and there’s a checkbox for smooth… but if selected smooth before you started making your game, it should already be set for smooth.


#35

Ahhhhh yes, thank you. I saw it now.

Yeah, none of them are smoothed. so that’s definitely not the problem…