Search Unity

NL/ENG let a ball roll with the arrow keys

Discussion in 'Getting Started' started by Euranium_, Dec 9, 2017.

  1. Euranium_

    Euranium_

    Joined:
    Dec 9, 2017
    Posts:
    10
    hallo,
    hello,

    ik ben Nederlands en wil een soort Arena game maken. ik wil een balletje 4 kanten op laten rollen. mijn
    I'm Dutch and i want to make a sort of Arena game. i want to roll a ball 4 directions with the arrow keys. my
    code is:(JavaScript)
    code is:(JavaScript)

    #pragma strict
    var rotationSpeed = 7;
    function Update ()
    {
    var playerRotationH : float = Input.GetAxis ("Horizontal") * rotationSpeed;
    playerRotationH *= Time.deltaTime;
    GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * playerRotationH);
    var playerRotationV : float = Input.GetAxis ("Vertical") * rotationSpeed;
    playerRotationV *= Time.deltaTime;
    GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * playerRotationV);
    }

    ik weet alleen niet hoe ik de onderste 3 regels kan aanpassen zodat ik het balletje ook verticaal kan laten rollen
    I only don't now how i can edit the last 3 rows, so like i can rool the ball vertical to.
    nu is het zo dat ik met de horizontale én de verticale pijltjes het balletje alleen horizontaal laat rollen
    Now i only can with the vertical ánd horizontal arrows the ball roll horizontal.

    kan iemand helpen?
    any help?

    groeten,
    greets,
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    In the second AddRelativeTorque call, try using Vector3.right or Vector3.left instead of Vector3.back.
     
    Euranium_ likes this.
  3. Euranium_

    Euranium_

    Joined:
    Dec 9, 2017
    Posts:
    10
    Thanks! i will try it!
     
  4. Euranium_

    Euranium_

    Joined:
    Dec 9, 2017
    Posts:
    10
    Hello,

    the script works now, but not really the good way. because I rotate the ball relative to the point above the ball. But that point moves because I rotate the ball. Is there a code with I can set every gameframe the abovest point as the relative point?

    thanks,

    P.S. I'm Dutch and 12 years old so i can't very good English. Sorry for that.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I think you should try going through the Roll-a-Ball Tutorial.

    (By the way, your English is amazing, especially for someone your age!)