Search Unity

force translation

Discussion in 'Scripting' started by Bolt, Mar 29, 2013.

  1. Bolt

    Bolt

    Joined:
    Dec 15, 2012
    Posts:
    296
    how can I force a movement transform.translate? I have a scene with an enemy that goes back and forth. I used Mathf.pingpong to bring you back. I want to make sure that every time you collide with something Invert its translation but is forced into Update. How can I do?
     
  2. ardo314

    ardo314

    Joined:
    Jul 7, 2012
    Posts:
    345
    Code (csharp):
    1.  
    2. void FixedUpdate(){
    3. transform.Translate(movementVector * direction);
    4. }
    5.  
    6. void OnCollisionEnter(){
    7. direction *= -1;
    8. }
    9.  
    Something liek that?
     
  3. Bolt

    Bolt

    Joined:
    Dec 15, 2012
    Posts:
    296
    This is what I want to accomplish, I hope you can understand it better $Immagine.jpg