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

#1 2012-04-29 16:07:04

KyleK7
Scratcher
Registered: 2011-06-14
Posts: 500+

Need help with yvelocity on a platformer

OK, I've got a platformer where the yvel variable won't work right. My character keeps bobbing up and down, like this:

             o
             |
-----------^---

Then gradually goes down to something like this:


             o   
-----------|------
              ^
and repeats over and over and over. Here's my scripts.

when gf clicked
forever
 change y by (yvel)
end

when gf clicked
forever
 change [yvel] by (-0.25)
 if <color [blue] is touching color [green]?>
  set [yvel] to [0]
 end
 if <(yvel) = (-5)>
  change yvel by (1)
 end
 if <color [red] is touching color [green]?>
  change [yvel] by (0.25)
  if <key [space] pressed?>
   repeat (5)
    change [yvel] by (1)
   end
  end
 end
end
Blue=head and red= body.

Last edited by KyleK7 (2012-04-29 16:32:50)


http://i46.tinypic.com/zwxnhh.gif

Offline

 

#2 2012-04-29 16:25:05

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Need help with yvelocity on a platformer

Try this  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#3 2012-04-29 16:32:11

KyleK7
Scratcher
Registered: 2011-06-14
Posts: 500+

Re: Need help with yvelocity on a platformer

Prestige wrote:

Try this  smile

That won't work. I'm using a sensor with two colors; one for the head and another for the body so that if he bumps his head, it'll stop going up.


http://i46.tinypic.com/zwxnhh.gif

Offline

 

#4 2012-04-30 20:57:07

Pikapika12
New Scratcher
Registered: 2012-04-22
Posts: 24

Re: Need help with yvelocity on a platformer

I'm only familiar with x velocity but.. I think that you should not use the -0.25! Instead you should use a forever if not key space pressed script, and then do repeat until not touching color blahblahblah, change the y Thingy by minus something. Did this help?
----
Lunastar-

Offline

 

#5 2012-04-30 21:54:23

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

Re: Need help with yvelocity on a platformer

when gf clicked
forever
change [yvel v] by (-0.2)
change y by (yvel)
if<<color [blue] touching color [green]?> or <color [red] touching color [green]?>>
set [y-vel v] to ((-0.5)*(y-vel))
change y by (y-vel)
if<color [blue] touching color [green]?>
change y by (y-vel)
if<<key [space v] pressed?> and <(y-vel) < (0)>>
set [yvel v] to (4)
end
end
That should do it  smile

P.S. You can just use one color with that script and replace the sensing blocks with "if< touching [green]?>"


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

Offline

 

#6 2012-05-01 02:10:34

letmethink
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: Need help with yvelocity on a platformer

I was thinking of, forever if Not Color red is touching color green, change y velocity by -o.2 and keep everything else the same

I might remove the change y velocity by 0.25


Clicky Clicky!!!               I am writing a book...             Look here

Offline

 

#7 2012-05-02 04:38:39

ExtremelyGamer
Scratcher
Registered: 2012-03-11
Posts: 1000+

Re: Need help with yvelocity on a platformer

start with something simple,

[scratchblocks]
when gf clicked
forever if touching color (blue is the background) and not touching color (brown is the ground)

change y by -1


"Submarines are like water like underwater airplanes" O_o

Offline

 

Board footer