Search Unity

Collision detection on offsetting texture

Discussion in 'Scripting' started by noocell, Feb 23, 2010.

  1. noocell

    noocell

    Joined:
    Mar 23, 2009
    Posts:
    104
    I have a flat mesh that just covers the outlines of a rectangle shape. On this perimetric mesh there is a texture and on the texture there are some car drawings that "move" along the borders of the screen (the user controls the offset of the texture along the mesh). The mesh has bones on it which bend it on the edges.

    My question is this: Given that the only thing that is moving is the texture along the mesh and I can not use
    colliders on the texture itself, how can I detect the collision of car drawings with other objects on the screen which are moving towards the mesh?

    Any ideas?
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The RaycastHit object returned by Physics.Raycast has a field that specifies the texture coordinate where the hit took place. If you can arrange to perform a raycast at the point of collision, you can get the texture coordinate and subtract the current texture offset to it to get the position on the un-shifted texture. Then, you can just test if the coordinate is inside the rectangle for the car, or do a pixel test against the car's colours, or whatever.
     
  3. noocell

    noocell

    Joined:
    Mar 23, 2009
    Posts:
    104
    Sounds tasty! I think it is going to work...

    Thanks!