therealnemis

12/3 class

Dec 2nd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Global space - directions are constant, we move relative to the plane. Rotate object - still the same
  2.  
  3. (upper tab above scene)
  4. Local space- directions are based upon the orientation of the cube
  5.  
  6. Drag sphere object onto Cube in the hierarchy
  7. cube is parent of sphere
  8.  
  9. New C# script attach to cube object. Call it cube script
  10.  
  11. public Transform sphereTransform
  12. >attach sphere to transform
  13. void Start(){
  14. sphereTransform.parent = transform;
  15. }
  16.  
  17. void Update(){
  18. transform.eulerAngles += new Vector3(0, 100 * Time.deltaTime, 0);
  19.  
  20. >>>>transform.eulerAngles += new Vector3(0, 1, 0) * Time.deltaTime;
  21. >>>>Vector3.up * 180 * Time.deltaTime
  22. }
  23.  
  24. Rotate cube 45 degrees and press play
  25.  
  26. void Update(){
  27. transform.Rotate(Vector3.up * Time.deltaTime * 180);
  28. }
  29.  
  30. now rotating about the local y axis
  31.  
  32. back to global
  33.  
  34. void Update(){
  35. transform.Rotate(Vector3.up * Time.deltaTime * 180, Space.World);
  36. transform.Translate (Vector3.forward * Time.deltaTime * 7);
  37. }
  38.  
  39.  
  40. Now it starts moving forward. If we add Space.World, it moves to global space and moves forward forever
  41.  
  42.  
  43. void Start(){
  44. sphereTransform.localScale = new Vector3 (2, 2, 2);
  45. }
  46.  
  47. or
  48. void Start(){
  49. sphereTransform.localScale = Vector3.one * 2;
  50. }
  51.  
  52. void Update(){
  53. if (Input.GetKeyDown(KeyCode.Space){
  54. sphereTransform.position = Vector3.zero;
  55. }
  56. }
  57. Why does it do this? It resets the position back to zero
  58.  
  59. instead
  60.  
  61. sphereTransform.localposition = Vector3.zero;
Advertisement
Add Comment
Please, Sign In to add comment