Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rolle the cube

Discussion in 'Scripting' started by abdoubelbala, Jul 24, 2014.

  1. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    Hi everbody I want to ask you about Example of a script that allow to my cube to move not to translate
    and please if you can write it with java script thank you
     
  2. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    i want the script do like that

    thank you
     
  3. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    any answers please help me
     
  4. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Code (CSharp):
    1. SomebodyWriteCodeForMe code = new SomebodyWriteCodeForMe ();
     
  5. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    That should do it
     
  6. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    There is a RotateAround function
    http://docs.unity3d.com/ScriptReference/Transform.RotateAround.html

    So you can have four offset positions for four directions you move. You'd have to store the current rotation point temporarily until the rotation is complete, otherwise the position will change during the rotation.

    Also when you complete the rotation I might round off the position to the spacing of the grid so you don't introduce cumulative floating point errors. (If it's important to stay on a grid.)
     
  7. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    thank you but i want to make my cube rotate translate and controlled by the user just like that
     
  8. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    i didnt undrstand what you mean i just want script do like that

    thank you
     
  9. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    any script please
     
  10. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    No one is simply going to write an entire script for you. If you try and need help then we show you what you're doing wrong or missing but you haven't even attempted to try and script it yourself.

    The user above showed you a link to the documentation for the function you'll need to use; he also told you a way to use it.

    You need to go learn the basics. Give it a go yourself. If you're still struggling then; come back and we'll help you out. You need to meet us half way
     
    abdoubelbala and landon912 like this.
  11. Hunter_W

    Hunter_W

    Joined:
    May 5, 2014
    Posts:
    57
    You need to rephrase the question

    "allow to my cube to move not to translate"
    "i want to make my cube rotate translate and controlled by the user"

    ???
     
  12. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,579
  13. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    write you are write i miss the basics but i have to learn it thank you so much i really apreciate
     
  14. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    Oh, I hadn't watched it past 23 seconds, so I assumed you wanted it to roll over, but when I watch the later part of that video I realize I don't understand what you want at all.
     
    abdoubelbala likes this.
  15. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    i want to make my cube rotate translate and controlled by the user just Like the tutorial Rolle The Ball
     
  16. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,579
    Did you watch the tutorial series? You should be able to do what you're asking if you watch it....
     
  17. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    Well if there's already a tutorial, we're not going to be any better than that.
    I would have guessed the difference between rolling a ball and rolling a cube is the cube rotates along the forward edge while the ball always rotates in the centre, which is why I mentioned the RotateAround function so you could change the rotation point.
     
    abdoubelbala likes this.
  18. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    So you inspired me to think of what game could be made with a rolling cube:
    http://gamejolt.com/games/puzzle/dice-roller/30941/

    So I had two Vector3, rotPoint and rotAxis. I had a float called rollingCount and a bool called rolling.

    In Update, if rolling is false then I do GetKeyDown on four direciton keys.
    If one of them is pressed, then I:
    1) set rolling to true (so I can't start a new roll until this roll is complete)
    2) set rollingCount to 90 (it needs to rotate 90 degrees)
    3) set rotPoint and rotAxis depending on which direction it is

    So still in Update, if rolling is true, then I
    1) use transform.RotateAround(transform.parent.TransformPoint(rotPoint),rotAxis,rotationSpeed);
    2) subtract rotationSpeed from rollingCount
    3) if rollingCount <=0 then I round off the position to the nearest 1 and the eulerAngles to the nearest 90, and set rolling back to false
     
    abdoubelbala likes this.
  19. abdoubelbala

    abdoubelbala

    Joined:
    Aug 4, 2012
    Posts:
    51
    thank you