Search Unity

ball jumping

Discussion in 'Scripting' started by Sam Shiels, Mar 28, 2007.

  1. Sam Shiels

    Sam Shiels

    Joined:
    Feb 25, 2007
    Posts:
    160
    How can I make a ball jump if you press the space bar.

    (The ball has a script very much like the ball rolling script in the Marble project).
     
  2. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
  3. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    i haven't looked at the marble project but you could also take a look at the fpswalker script. set the jump button in the input manager to spacebar (think that's the default).

    snippet...
    Code (csharp):
    1.  
    2. if (Input.GetButton ("Jump"))
    3. {
    4.      moveDirection.y = jumpSpeed;
    5. }
    6.  
     
  4. Sam Shiels

    Sam Shiels

    Joined:
    Feb 25, 2007
    Posts:
    160
  5. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Hi Sam... little by little! :)

    As you progress and continue on your project, you'll find that making games is all about those little cases. Sadly, there is no "duplicate reality" script (not yet heh!)

    In the meantime, I recommend that you take a look at the tutorials (via the link above) and work through them. They are very easy to follow and I'm confident doing so will help you in many wonderful ways.

    Once you do, to address your comment, you'll want to check if your object is on the ground, and if it is, only then check for button input (via the jump button). The FPS script that Pete mentions does this.
     
  6. Sam Shiels

    Sam Shiels

    Joined:
    Feb 25, 2007
    Posts:
    160
    OK! Thanks!

    (I've looked at tuts).
     
  7. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    ah yes, sorry! didn't mean to imply that would work out of the box. just pointing it out... i hear duplicate reality(tm) is slated for 2.0 (oh don't go quoting me on that!) :D
     
  8. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    ooooh juicy!!

    ::Casemon:: slides over to the Gossip forum for some "a little bird told me" posting... :)

    note re: "little bird" i'm not assuming anything about your stature Pete, it's just that calling you "big bird" would have been too weird...
     
  9. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    :D

    sam, forgot to mention, iirc the fps script is set up to use the character controller. i believe isgrounded is specific to the character controller. you might need to cast a ray down to get the distance (or something) if you aren't using the cc. double check for yourself though - i'd have to look and i didn't. anyway... good luck with it!