This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-09 17:44:53

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

I need a wall jumping script using trig

I need a wall jumping script that involves trigeometry...
Also please explain the script...


Get ready for domination of:  tongue

Offline

 

#2 2012-04-09 17:49:16

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2012-04-09 17:52:12

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig

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...


Get ready for domination of:  tongue

Offline

 

#4 2012-04-09 18:01:44

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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  hmm

Last edited by MoreGamesNow (2012-04-09 18:01:55)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-04-09 18:03:12

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig

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  hmm

It's ok... I can use wall detecting... Can you give me the script?


Get ready for domination of:  tongue

Offline

 

#6 2012-04-09 18:17:34

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig

bump!


Get ready for domination of:  tongue

Offline

 

#7 2012-04-09 20:00:40

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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).

http://i44.tinypic.com/11ju9o7.png

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2012-04-09 20:15:13

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: I need a wall jumping script using trig

http://scratch.mit.edu/projects/AtomicBawm3/2184464

Here you go, I did this a while back...hope that helps!


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#9 2012-04-09 20:22:22

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-04-09 20:56:54

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: I need a wall jumping script using trig

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.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#11 2012-04-10 17:53:13

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig


Get ready for domination of:  tongue

Offline

 

#12 2012-04-11 14:01:42

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig

Bump! Look above for details...


Get ready for domination of:  tongue

Offline

 

#13 2012-04-12 00:14:16

LiquidMetal
Scratcher
Registered: 2011-06-15
Posts: 500+

Re: I need a wall jumping script using trig

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

 

#14 2012-04-12 06:57:41

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: I need a wall jumping script using trig

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.  smile


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#15 2012-04-12 13:08:12

LiquidMetal
Scratcher
Registered: 2011-06-15
Posts: 500+

Re: I need a wall jumping script using trig

Ok, What do I do with the slope in order to get the bounce?  Something with X and Y velocity?

Offline

 

#16 2012-04-12 14:07:32

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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  hmm

Last edited by MoreGamesNow (2012-04-12 14:18:06)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#17 2012-04-12 15:42:49

LiquidMetal
Scratcher
Registered: 2011-06-15
Posts: 500+

Re: I need a wall jumping script using trig

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  hmm

What is

(new angle)
?

And this should go in the sprite that is bouncing?

Last edited by LiquidMetal (2012-04-12 15:44:51)

Offline

 

#18 2012-04-12 16:28:45

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#19 2012-04-12 17:21:36

LiquidMetal
Scratcher
Registered: 2011-06-15
Posts: 500+

Re: I need a wall jumping script using trig

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

 

#20 2012-04-12 17:36:08

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: I need a wall jumping script using trig

i'll work on one. give me a little time.


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#21 2012-04-12 18:34:48

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

Here you go.  Press SPACE to render the walls (Flash player wouldn't detect the walls when they were rendered every frame  sad   ).


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#22 2012-04-12 18:38:28

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig

MoreGamesNow wrote:

Here you go.  Press SPACE to render the walls (Flash player wouldn't detect the walls when they were rendered every frame  sad   ).

no like a platformer...


Get ready for domination of:  tongue

Offline

 

#23 2012-04-12 18:53:28

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

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  sad   ).

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  smile   I was just horribly confused; I didn't realize this thread had evolved into two different questions xD.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#24 2012-04-12 18:59:23

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: I need a wall jumping script using trig

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  sad   ).

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  smile   I was just horribly confused; I didn't realize this thread had evolved into two different questions xD.

See my earlier post...  smile


Get ready for domination of:  tongue

Offline

 

#25 2012-04-12 19:13:08

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: I need a wall jumping script using trig

Try my link again.  Should be good now  smile


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer