I'm not sure why you'd need trigonometry (unless you're bouncing off of sloped walls?). With only right angles, all you need is velocities.
when gf clicked forever receive inputs change x by (xvel) if<touching [wall v]?> set [xvel v] to ((xvel)*[-1]) change x by (xvel) end change y by (yvel) if<touching [wall v]?> set [yvel v] to ((yvel)*[-1]) change y by (yvel) end
Offline
MoreGamesNow wrote:
I'm not sure why you'd need trigonometry (unless you're bouncing off of sloped walls?). With only right angles, all you need is velocities.
when gf clicked forever receive inputs change x by (xvel) if<touching [wall v]?> set [xvel v] to ((xvel)*[-1]) change x by (xvel) end change y by (yvel) if<touching [wall v]?> set [yvel v] to ((yvel)*[-1]) change y by (yvel) end
Yes I am bouncing off sloped walls...
Is there a way to do this without a wall sensor, because I hate programming wall sensors...
Offline
coolhogs wrote:
Yes I am bouncing off sloped walls...
Is there a way to do this without a wall sensor, because I hate programming wall sensors...
If you want to do it without sensing and if the walls are sloped, things could get tricky.
You'll need to know the slope of the wall you're touching first. I'm not sure how to do that without sensing
Last edited by MoreGamesNow (2012-04-09 18:01:55)
Offline
MoreGamesNow wrote:
coolhogs wrote:
Yes I am bouncing off sloped walls...
Is there a way to do this without a wall sensor, because I hate programming wall sensors...If you want to do it without sensing and if the walls are sloped, things could get tricky.
You'll need to know the slope of the wall you're touching first. I'm not sure how to do that without sensing
It's ok... I can use wall detecting... Can you give me the script?
Offline
I'll have to get the ol' paper and pencil out. I can tell you this though: trying to approximate the slope of a wall, even with sensing, will be just that, an approximate (seriously, like 30 degrees of error).
Basically, you find the angle of the wall (the thick line) and the direction the sprite is moving (dashed line). Then you reset the x and y velocities with the same magnitude/hypotenuse, but with values according to the new angle. To be honest, I've tried this once or twice but haven't been successful.
Last edited by MoreGamesNow (2012-04-10 13:29:21)
Offline
http://scratch.mit.edu/projects/AtomicBawm3/2184464
Here you go, I did this a while back...hope that helps!
Offline
AtomicBawm3 wrote:
http://scratch.mit.edu/projects/AtomicBawm3/2184464
Here you go, I did this a while back...hope that helps!
This is a great way to calculate the redirection of the bounce. But you still need to find the slope of the wall. What I've tried (admittedly, it failed) was to change the sprite's y position and x position by ones and try to find out the slope based on how many x/y positions it can change before hitting the wall again (I hope that made sense). Doing this all real time is, of course, a problem. Maybe you could make some sort of "slope of wall" sensing costume?
Offline
MoreGamesNow wrote:
AtomicBawm3 wrote:
http://scratch.mit.edu/projects/AtomicBawm3/2184464
Here you go, I did this a while back...hope that helps!This is a great way to calculate the redirection of the bounce. But you still need to find the slope of the wall. What I've tried (admittedly, it failed) was to change the sprite's y position and x position by ones and try to find out the slope based on how many x/y positions it can change before hitting the wall again (I hope that made sense). Doing this all real time is, of course, a problem. Maybe you could make some sort of "slope of wall" sensing costume?
I would use two sprites like this set up, one at +5 the other at -5 x of the player and they both have a vertical collision with the wall. Then you use the slope of the line between them.
Offline
This should help!
http://scratch.mit.edu/projects/coolhogs/2460631
Offline
If I know the direction of an object which is vertical at 90 degrees, what is the slope relative to the direction? I'm trying to make this with a separate slope sensing sprite but it is a bit slow at the moment.
Offline
LiquidMetal wrote:
If I know the direction of an object which is vertical at 90 degrees, what is the slope relative to the direction? I'm trying to make this with a separate slope sensing sprite but it is a bit slow at the moment.
The slope of a line is the tangent of it's direction.
Offline
Ok, What do I do with the slope in order to get the bounce? Something with X and Y velocity?
Offline
(2 x (angle of wall)) - (angle of initial velocity) = (angle of final velocity)
This seems to work. To find the new velocities, do this
point in direction (((angle of wall)*(2)) - (direction)) set [c v] to ([sqrt v] of (((xvel)*(xvel))+((yvel)*(yvel)))) set [xvel v] to ((c)*([sin v] of (new angle))) set [yvel v] to ((c)*([cos v] of (new angle)))I hope that works, I don't have Scratch on the computer I'm using
Last edited by MoreGamesNow (2012-04-12 14:18:06)
Offline
MoreGamesNow wrote:
Code:
(2 x (angle of wall)) - (angle of initial velocity) = (angle of final velocity)This seems to work. To find the new velocities, do this
point in direction (((angle of wall)*(2)) - (direction)) set [c v] to ([sqrt v] of (((xvel)*(xvel))+((yvel)*(yvel)))) set [xvel v] to ((c)*([sin v] of (new angle))) set [yvel v] to ((c)*([cos v] of (new angle)))I hope that works, I don't have Scratch on the computer I'm using
What is
(new angle)?
Last edited by LiquidMetal (2012-04-12 15:44:51)
Offline
LiquidMetal wrote:
What is
(new angle)?
And this should go in the sprite that is bouncing?
Oh, sorry:
point in direction (((angle of wall)*(2)) - (direction)) set [c v] to ([sqrt v] of (((xvel)*(xvel))+((yvel)*(yvel)))) set [xvel v] to ((c)*([sin v] of (direction))) set [yvel v] to ((c)*([cos v] of (direction)))And yes.
Offline
It is not working!
See it here.
EDIT: Wait is angle of wall the slope or the direction?
EDIT: Maybe because I did not put in the rotation thing?
Last edited by LiquidMetal (2012-04-12 17:28:03)
Offline
Here you go. Press SPACE to render the walls (Flash player wouldn't detect the walls when they were rendered every frame ).
Offline
MoreGamesNow wrote:
Here you go. Press SPACE to render the walls (Flash player wouldn't detect the walls when they were rendered every frame ).
no like a platformer...
Offline
coolhogs wrote:
MoreGamesNow wrote:
Here you go. Press SPACE to render the walls (Flash player wouldn't detect the walls when they were rendered every frame ).
no like a platformer...
I just remixed LiquidMetal's project. Do you want me to add gravity?
@LiquidMetal: do you have a separate question from coolhogs' question? If so, it's better to start your own thread than to piggy back onto another one I was just horribly confused; I didn't realize this thread had evolved into two different questions xD.
Offline
MoreGamesNow wrote:
coolhogs wrote:
MoreGamesNow wrote:
Here you go. Press SPACE to render the walls (Flash player wouldn't detect the walls they were rendered every frame ).
no like a platformer...
I just remixed LiquidMetal's project. Do you want me to add gravity?
@LiquidMetal: do you have a separate question from coolhogs' question? If so, it's better to start your own thread than to piggy back onto another one I was just horribly confused; I didn't realize this thread had evolved into two different questions xD.
See my earlier post...
Offline
Try my link again. Should be good now
Offline