Is there a Scratch script or function that can detect the angle of a wall?

176 views Asked by At

Im working on a 2D, non-scrolling, portal-themed platformer in scratch, and I was wondering if there was a function or script that I could make to help find the angle of a wall. As it stands, the portals do "stick" to the walls, but I want them to be perfectly level with the wall.

(link to the project for more details, its still in development: https://scratch.mit.edu/projects/899664020/)

Also, I have some coding knowledge, so if your answer isn't in a scratch coding language, but is still compatible with it, I can most likely decipher it.

I haven't tried anything yet, mostly because I don't know what to do, or how to accomplish it. I did try googling for some similar questions/answers but got nothing.

EDIT: I think what I'm looking for is a form of raycasting, so It can detect any angle without having to do any manual work.

3

There are 3 answers

5
Vlad Feinstein On

I did not understand exactly what is the wall you are talking about, and how it is specified in your code.

I will assume that you can find the slope of that wall. You can get the angle from there using arcsine function. It's called asin in Scratch.

0
bchyou On

You can try something like this: https://scratch.mit.edu/projects/939684578/ I didn't put it in run without screen refresh so that you can see what's going on.

0
Vedaant Arya On

I'd suggest to create a base wall element (could be a simple line), then orient it near surfaces where you want your portal to stick.

Then, you can broadcast an event on a hit, and store the hit object's orientation value in a variable. The newly created portal can read the last set orientation value.

Demo for broadcasting: https://scratch.mit.edu/projects/966207615