I’m working on a 2D game with sprites.
I have this idea, to have an animated sprite drive a position of some other gameObject within the scene.
I really don’t want to deal with manual sprite animation synchronization with multiple other simultaneous unity animations.
So I wonder if the follwoing is possible/feasible?
- Have a certain/special color pixel within the sprite.
- Have the shader detect and somehow report the location of this pixel. (<- this is step I’m currently struggling with)
- Have a script get the worldspace position of said pixel and reposition the needed gameobject to given location.
This way, I could drive the position of other objects purely via sprite frame animation without the need to create other animations in Unity. And later changing the movement would be super easy - I would only need to change the visual sprite.
So is this approach feasible? Is it somehow possible to get a numerical variable from a shader? Or is there some other way to get the location of a specific pixel?
Example.
Let’s say I have the following sprite sheet for an animation.
I have chosen a special color (magenta in this case) for my special sprite pixel.
So now I want to somehow get the location of this pixel in every frame and use this data in a script (e.g. to position some other gameobject).
I have tinkered with custom shader code before, so I have some idea of how it all works, but I don’t know if and how it’s possible to read a variable (pixel location) from a shader.
