Search Unity

Totaly newbie Q

Discussion in 'Editor & General Support' started by whiteb, Mar 21, 2008.

  1. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    I am totaly new to Unity but after trying it for 10 days i am already convinced to buy one.

    But that was'nt my question anyway ... i am trying different things and methods with Unity and now i cannot move sphere on a plane. How do i do that? I have a script that is rotating the ball but don't know how to force it to roll on the plane.

    Any hepl will be a big step forward.

    Thanx

    Peter
     
  2. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    This is the kind of thing you probably want. Also make sure a rigidbody is attached to the sphere.

    Code (csharp):
    1. function FixedUpdate () {
    2.     var ver = Input.GetAxis("Vertical");
    3.     rigidbody.AddRelativeTorque (0,0,ver);
    4. }
     
  3. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    Thanx for the quick answer. I applied the script to the sphere but nothing seems 2 happen. The sphere has a rigidbody. Is there anything else i need to do.

    Anyone can Help?????
     
  4. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    This script applys rotational force when you use the up/down keys or w/s keys (if you haven't changed the input config). Press the keys and it should roll.

    If you want to have the ball always roll go for something like this:

    Code (csharp):
    1. function FixedUpdate () {
    2.    rigidbody.AddRelativeTorque (0,0,1);
    3. }
     
  5. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    OK thanx,

    i tried that and yes it rolls but what i want to happen is when i press arrows it starts to move and rolls the direction it moves. Just like in Marble Blast game :)

    http://www.youtube.com/watch?v=258M9RTXzSM

    Sorry for so many questions
     
  6. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    like this?

    Code (csharp):
    1.  
    2. var speed = 0.00;
    3. var force = 0.00;
    4.  
    5. function FixedUpdate ()
    6. {
    7.     var oldAngle = Camera.main.transform.localEulerAngles.x;
    8.     Camera.main.transform.localEulerAngles.x = 0;
    9.     var spin = Camera.main.transform.TransformDirection(Vector3(Input.GetAxis("Vertical") * speed, 0, -Input.GetAxis("Horizontal") * speed));
    10.     Camera.main.transform.localEulerAngles.x = oldAngle;
    11.     rigidbody.AddTorque((spin - rigidbody.angularVelocity) * force);
    12. }
    13.  
     
  7. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    :D it works but still...sorry..

    it jumps funny and doesn't move like it should. What other scripts should i add? Should there be a character controller.
     

    Attached Files:

  8. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    try getting rid of all those scripts and just use the one i provided above
     
  9. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    Removed all scripts and left just yours... still funny jittery movements.
     
  10. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    can you make a webplayer and upload it
     
  11. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    here i made a unity package..... is this what you are trying to get at?
     

    Attached Files:

  12. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    That is exactly what i was trying to do. I didn't have the Main Camera Mouse Orbit script (is it a standard script that comes with Unity - i just have a trial version). And in the SphereCollider the Center XYZ position data... is that important?

    Anyway, thank You very much drag0nsphere. Now i will move forward ;)

    Thanx again.
     
  13. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    im not sure if it comes with the trial...... yes you need the sphere collider or it will go through the plane.
     
  14. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    Anyway i will buy it after trial :). Last question, how can i make it jump, i checked the input settings and it is OK (spacebar as jump button) or is something else i need to do?

    Peter
     
  15. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    something like this:
    Code (csharp):
    1.  
    2.  if (Input.GetButtonDown ("Jump")) {
    3.         rigidbody.velocity.y = 10;
    4.       }  
    5.  
     
  16. whiteb

    whiteb

    Joined:
    Mar 11, 2008
    Posts:
    13
    You are saving my life :). I hop i'll be able to pay back for that. Can i add this code to your Control script? Or should i do it other way?

    thanx in advance.
     
  17. drag0nsphere

    drag0nsphere

    Joined:
    Nov 7, 2007
    Posts:
    285
    yep you can add it to the control script.