# How to make this in unity?

Hello hello!
I wanted to do the following effect but I couldn’t, if anyone knows how to do it and can help me I would appreciate it.

The idea is, depending on the collision of two objects (sprites), “object1 is the green rectangle” and “object 2 is the red”, object2 would have to know the point at which (creating an imaginary line) object1 would come out on the other side of the object.

I wanted to create this effect to be able to calculate where an object enters and exits and to be able to change the texture of the object2 itself at the entry and exit point

Using add force should just work if you use rigidbodies.
Otherwise look into lerp/slerp/smoothdamp i think

Yes, I thought about it but I would need to know the exact two points to change the texture at that point

You mention “sprites colliding” which, of course, they don’t, colliders do so I’m going to assume you’ll use a PolygonCollider2D only in which case, the attached project shows you how to perform an intersection clipping that retrieves all the intersections of a single ray which you can substitue for a ray at the hit point in the direction of the velocity you were moving before you came into contact.

This gathers the clip-points then sorts them time-wise with the first being the first hit and the last being the last hit. In your case you only want these so you can simply use them.

This gives you intersection points. In terms of textures, that’s obviously nothing to do with physics so you’d have to correlate the clip-points with the sprite and texture yourself.

Clearly though, this is for a ray enter/exit which isn’t your other collider shape. You can do this another way which is, instead of a ray, you perform a physics query such as BoxCast to perform a check in in the opposite direction back along that ray to see where it hits the other side.

Note: If you want this for any type of collider then things get much more complex.

Hope this helps.

3 Likes