Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Calculating surface normal
- rdococ
- Scratcher
500+ posts
Calculating surface normal
I am creating a
bounce off [Sprite1 v] :: motionblock in BYOB, and I would like to calculate the surface normal of the sprite within the block definition, where the collision is going to take place. Using
([direction v] of [Sprite1 v])works, but only for lines that are vertical in the paint editor. I've never seen a problem like this on any other website, so this might be tricky, or even impossible, to solve. Does anyone have a solution? If so, please post it here.
Last edited by rdococ (April 9, 2015 00:17:26)
The royal blue colour scheme. Be aesthetic
Links: Search the forums.
Posts: Make cloud variables suck less | Recursive broadcasts | Sprite-local pen
Projects: YaSL tiny LISP with first-class functions & macros | Object-oriented language in Scratch | Complex, split-complex & dual numbers visualized | node logic simulator
- MegaApuTurkUltra
- Scratcher
1000+ posts
Calculating surface normal
Hmm surface normal? Well if you have a defined polygon or curve, it's easy, but are you asking how to do it for any arbitrary raster image?
$(".box-head")[0].textContent = "committing AT crimes since $whenever"
- rdococ
- Scratcher
500+ posts
Calculating surface normal
Yes, in a certain part where the collision must take place. Hmm surface normal? Well if you have a defined polygon or curve, it's easy, but are you asking how to do it for any arbitrary raster image?
The royal blue colour scheme. Be aesthetic
Links: Search the forums.
Posts: Make cloud variables suck less | Recursive broadcasts | Sprite-local pen
Projects: YaSL tiny LISP with first-class functions & macros | Object-oriented language in Scratch | Complex, split-complex & dual numbers visualized | node logic simulator
- MegaApuTurkUltra
- Scratcher
1000+ posts
Calculating surface normal
You could attempt to vectorize the image and then detect the normal based on the line / curve thereYes, in a certain part where the collision must take place. Hmm surface normal? Well if you have a defined polygon or curve, it's easy, but are you asking how to do it for any arbitrary raster image?
$(".box-head")[0].textContent = "committing AT crimes since $whenever"
- rdococ
- Scratcher
500+ posts
Calculating surface normal
That sounds hard to do in something like BYOB. Do you know of a fast way to do this?You could attempt to vectorize the image and then detect the normal based on the line / curve thereYes, in a certain part where the collision must take place. Hmm surface normal? Well if you have a defined polygon or curve, it's easy, but are you asking how to do it for any arbitrary raster image?
The royal blue colour scheme. Be aesthetic
Links: Search the forums.
Posts: Make cloud variables suck less | Recursive broadcasts | Sprite-local pen
Projects: YaSL tiny LISP with first-class functions & macros | Object-oriented language in Scratch | Complex, split-complex & dual numbers visualized | node logic simulator
- MegaApuTurkUltra
- Scratcher
1000+ posts
Calculating surface normal
No. You should just only support vector for collision (no embedded bitmaps either), and use the paths to calculate normals.That sounds hard to do in something like BYOB. Do you know of a fast way to do this?You could attempt to vectorize the image and then detect the normal based on the line / curve thereYes, in a certain part where the collision must take place. Hmm surface normal? Well if you have a defined polygon or curve, it's easy, but are you asking how to do it for any arbitrary raster image?
$(".box-head")[0].textContent = "committing AT crimes since $whenever"
- Superdoggy
- Scratcher
1000+ posts
Calculating surface normal
You could attempt to vectorize the image and then detect the normal based on the line / curve thereYes, in a certain part where the collision must take place. Hmm surface normal? Well if you have a defined polygon or curve, it's easy, but are you asking how to do it for any arbitrary raster image?
No wow that's waaaay complicated for Scratch.
Here's what you do:
Move on X axis. On collision with wall, back out X so that the ball is no longer collided. Then move back 3 pixels into the wall. After that, move on the Y axis to see how many pixels it takes to get back out of the wall. If it takes too many pixels to get back out of the wall, then it's probably a vertical wall.
Move on Y axis. On collision with wall, back out Y so that the ball is no longer collided. Then move back 3 pixels into the wall. After that, move on the X axis to see how many pixels it takes to get back out of the wall. If it takes too many pixels to get back out of the wall, then it's probably a horizontal wall.
With the slopes of the lines calculated by pixel collisions, the proper velocity vector can be calculated. Here's an unfinished link to a demo thingy: https://scratch.mit.edu/projects/36255524/
- gtoal
- Scratcher
1000+ posts
Calculating surface normal
You could move the sprite +/-1 from the initial position and the +/-2, etc., and test at each offset for touching. This would generate a boundary of touching, to which you could then attempt to fit a line and subsequently determine a normal to that line. But with a line that is only a few pixels long, it would be a very approximate solution. I am creating abounce off [Sprite1 v] :: motionblock in BYOB, and I would like to calculate the surface normal of the sprite within the block definition, where the collision is going to take place. Using([direction v] of [Sprite1 v])works, but only for lines that are vertical in the paint editor. I've never seen a problem like this on any other website, so this might be tricky, or even impossible, to solve. Does anyone have a solution? If so, please post it here.
G
- nedulaal3
- Scratcher
4 posts
Calculating surface normal
hello i will just use the vector calculation from grffipatch's physics tutorial
- rdococ
- Scratcher
500+ posts
Calculating surface normal
Dang this is a MASSIVE necropost hello i will just use the vector calculation from grffipatch's physics tutorial
The royal blue colour scheme. Be aesthetic
Links: Search the forums.
Posts: Make cloud variables suck less | Recursive broadcasts | Sprite-local pen
Projects: YaSL tiny LISP with first-class functions & macros | Object-oriented language in Scratch | Complex, split-complex & dual numbers visualized | node logic simulator
- Discussion Forums
- » Advanced Topics
- » Calculating surface normal