Rotate a gameobject every time it collides with an “a” tag collider until the player does not press any key

I have tried with the code below, but the rotation is null (I suppose that the rotation happens only for a single frame, the one where the gameobject collides).

Vector3 cent;
float speed = 5f;
public GameObject center;
void Start () {
	cent = new Vector3 (0,0,1);

void OnTriggerEnter2D(Collider2D col)
    if(col.tag == "a")
        rb.velocity =;
        rb.Sleep ();
        transform.RotateAround (center.transform.position, cent, speed *Time.deltaTime);


I don’t know if my supposition is right, however I can not satisfy what I’m try to do. It would be appreciate if someone could help me towards the solution, or maybe even correct my code.

I’m not entirely sure what you are trying to accomplish, but OnTriggerEnter2D() only runs a single time upon entering a trigger collider. To trigger again, the object must first leave the trigger, then enter it again.

To continually rotate while inside a collider, use OnTriggerStay2D(). Also, I don’t think that transform.RotateAround() is necessary in this situation. transform.Rotate() is simpler and should get the job done.

As @Bacon004 said very well, @ftdev do try his suggestion. I have another solution to this. Really not sure if you are leaving the collider “a” to reset and detect collision again. But if you want gameObject to keep rotating once it has enter collision with “a” then do this in your OnTriggerEnter function,

if (col.CompareTag("a") ) {
       rb.velocity =;
       InvokeRepeating("Funtion Name", invokeTime, invokeRate);

And then outside in your class create a Function which you want to keep repeating and also use a bool or something in it to check if a key is pressed or not. Hope this was helpful.