How to translate the platforms in the opposite direction as soon as they are blocked by solid objects?

Good morning ,

When the platforms sometimes translate they collide during their translation with the player or other solid game objects (with trigger false), I would like in these two cases that the platforms translate in the opposite direction as soon as they encounter a solid object or stop their translations and remain on site with possibility of translation later on in the opposite direction only .

how to implement please , the most ideal and correct solution for it?

Thank you very much ,

Cordially .

You could attach a script like this to your platforms

void OnCollisionEnter(Collision other)
{
    if(other.gameObject.CompareTag("Platform") 
    {
        //Call a function in your platform translate script to change the translate direction
    }
}

You can change the “Platform” tag to whatever object you want. These objects will cause the platforms to change direction after colliding with it. If your game is using 2D physics, just change “Collision” to “Collision2D”.

If you only want the platforms to reverse direction if they collide from a particular direction, you can use other.contacts to get the point of contacts between the 2 colliding objects.

If you want both objects to stop before translating in the opposite direction, you could make a function like this in your platform translate script

public void OnCollideWithOtherPlatform()
{
    enabled = false; //This is to stop your platforms from translating
    Invoke("ContinueTranslation", 2.0f); //2.0f is the amount of time u want the platforms to stop for
}

void ContinueTranslation()
{
    enabled = true;
}

You would call OnCollideWithOtherPlatform() in the OnCollisionEnter function in the 1st script

Hope i understood your question correctly and that this helps!

Hello GenericToast,

thank you infinitely, you almost understood the question (I have wrongly expressed the problem),

I will give you an example to better understand the problem:

the platform translates to the right during its translation it can be blocked by any solid object including the player according to the level design,
 
in this case either it does not translate anymore from the blocking before it retranslate after a certain time in any of the other 3 senses where the platform is not yet blocked, or it translates directly without waiting in the 'one of the 3 remaining directions or sens where it is not yet blocked,

the blocking of the platform can be done in one direction (here only on the right) or in a maximum of two directions (eg right and up) and can in this case retranslater in the remaining directions where it is still free and not blocked,
 
another thing is it a good idea to implement this function in the oncollisionenter2d platforms ? is it better in general to add rigidbody2d for any gameobject other than player ? and without rigidbody2d collision not detected between 2 gameobjets in this case that do not include the player,

please if you do not mind giving me the full source code of the ideal solution to better understand it,

Thank you for your understanding.