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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unity 3d Programming Video Tutorials

Discussion in 'Made With Unity' started by dklompmaker, Feb 8, 2010.

  1. dklompmaker

    dklompmaker

    Joined:
    Sep 12, 2008
    Posts:
    80
    I am creating some video tutorials for programming concepts in Unity. The first video in a series that I aim to put together is basic dynamic obstacle avoidance programming.

    This tutorial covers basic ray casting concepts and how to apply information received into rotations. Future videos will be more complex and discuss the creation of artificial intelligence classes to handle the work of obstacle avoidance.

    This is my first video tutorial so let me know what you think.

    Click below to watch the video:
    http://vimeo.com/9304844
     
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I gave it a quick look, nicely done. Any plans for posting the code?
     
  3. dklompmaker

    dklompmaker

    Joined:
    Sep 12, 2008
    Posts:
    80
    In later videos I will include the code as it will be cleaner and more modular. But here is some basic code to play around with as it pertains to this video.

    Code (csharp):
    1.  
    2. var target : Transform;
    3. var repelForce : int = 20; // The force of which the object is pushed
    4.  
    5.  
    6. function Update(){
    7. var dir = (target.position - transform.position).normalized;
    8. var hit : RaycastHit;
    9. var leftRay = transform.position;
    10. var rightRay = transform.position;
    11. leftRay.x -= 2;
    12. rightRay.x += 2;
    13.  
    14. if(Physics.Raycast(transform.position, transform.forward, hit, 20)){
    15.      if(hit.transform != transform){
    16.          Debug.DrawLine(transform.position, hit.point, Color.red);
    17.           dir += hit.normal * repelForce;
    18.      }
    19. }
    20.  
    21. if(Physics.Raycast(leftRay, transform.forward, hit, 20)){
    22.      if(hit.transform != transform){
    23.           Debug.DrawLine(leftRay, hit.point, Color.red);
    24.           dir += hit.normal * repelForce;
    25.      }
    26. }
    27.  
    28. if(Physics.Raycast(rightRay, transform.forward, hit, 20)){
    29.      if(hit.transform != transform){
    30.           Debug.DrawLine(rightRay, hit.point, Color.red);
    31.           dir += hit.normal * repelForce;
    32.      }
    33. }
    34.  
    35. var rot = Quaternion.LookRotation(dir);
    36. transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime);
    37. transform.position += transform.forward * 20 * Time.deltaTime;
    38.  
    39. }
    40.  
    41.  
    This is not the cleanest code but it will serve as a starting point.
     
  4. absolutebreeze

    absolutebreeze

    Joined:
    Feb 7, 2009
    Posts:
    490
    Nice tutorial - and well put together :)

    Thank you :)
     
  5. Wadoman

    Wadoman

    Joined:
    Dec 8, 2007
    Posts:
    336
    Wow very nice tutorial and very appreciated. I look forward to anymore you come up with.
     
  6. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    good stuff, keep them coming! :)
     
  7. MatthewJCollins

    MatthewJCollins

    Joined:
    Dec 3, 2009
    Posts:
    372
    Nice, thanks dklompmaker! I look forward to seeing more.
     
  8. scarletsnake

    scarletsnake

    Joined:
    Nov 27, 2009
    Posts:
    106
    Excellent! No needless code input, easy to understand and implement, and to the point. Great work! I'm jumping aboard here with everyone who's waiting for your next tutorials.
     
  9. psyclone

    psyclone

    Joined:
    Nov 17, 2009
    Posts:
    245
    Nice tutorial, simple and easy to understand. Cant wait for the rest.... No pressure :)
     
  10. kingrat

    kingrat

    Joined:
    Dec 23, 2010
    Posts:
    93
    How would you change the script so the ai object first needs to collide with object 'subtarget' before it can reach its main target. For 'subtarget' the collider it has would be a trigger.

    Can somebody plz alter the script for me since i am no expert at scripting.

    Thanks very much
     
  11. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    936
    Nice tutorial thanks!

    ...but your website is not working.
     
  12. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Very nice!
     
  13. deepshit

    deepshit

    Joined:
    Jul 12, 2010
    Posts:
    9
  14. thellama

    thellama

    Joined:
    Mar 25, 2010
    Posts:
    360
    Very nice and easy to follow. One of my weaknesses is programming AI. This seems like a great places to start, Obstacle avoidance is key :D
     
  15. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,546
    And one of my weaknesses is babes with see-through clothing. Where do I get more of your avatar pic
     
  16. Betelgeuze

    Betelgeuze

    Joined:
    Dec 30, 2010
    Posts:
    94
    as someone who has no experience with this (just an artist) this is really great to learn something new!
     
  17. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    Very helpful- thanks a lot for posting it!
     
  18. theecoop

    theecoop

    Joined:
    Jan 30, 2011
    Posts:
    2
    dklompmaker, Thanks I am just learning so I found even at a noob stand point I could understand what was happening.
     
  19. kweiko

    kweiko

    Joined:
    Mar 9, 2010
    Posts:
    103
    I second that! :)