- Home /
 
 
               Question by 
               EmpI · Dec 19, 2014 at 11:05 PM · 
                triggerrigidbody2dvelocitydirection  
              
 
              Set Object Rotation based on Collision (2D)
So now I am looking to get an object to, upon colliding (or in this case entering the trigger) with an object with a specific tag, that the object's velocity be set to move the object in the direction the object it collided with was previously facing. Put simply, it's inheriting the direction of what it's colliding with, with no loss in speed.
Here's what my code looks like when I attempt this
     void OnTriggerEnter2D(Collider2D other){
             if(other.gameObject.tag == "Reflector"){
                 vel = rigidbody2D.velocity;
                 dir = other.transform.rotation.eulerAngles;
                 dir = dir.normalized;
 
                 rigidbody2D.velocity = vel.magnitude * dir;
 }
 }
 
               What am I doing wrong?
               Comment
              
 
               
              Your answer