Hello Guest

Author Topic: Change sprite depending on alingnment/direction  (Read 4032 times)

Der_Kevin

  • Newbie
  • *
  • Posts: 8
    • View Profile
Change sprite depending on alingnment/direction
« on: July 12, 2013, 10:56:54 am »
Hey guys.
Iam currently working on a top down racing game and i have a following problem:
I want to change the sprite of my car, based on the direction which it is driving.
why? because i want no real light calculation in my game.

for the movement i just simply use the free unity car tutorial from the asset store, changed the model to a sprite and put a second black and blured sprite underneath it to fake a drop shadow

but still i want to have the illusion of a light so i want to paint the light direct onto the sprite. also it need a tranistion between the changing sprite so that it loooks nice and smooth

here is a small graphic so i can show you what i mean:



the white light is not a light, its just an example for you to see where the sund normaly would come from. but there should be no light in the scene

I would be verry thankfull if you can help me out with that

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Change sprite depending on alingnment/direction
« Reply #1 on: July 12, 2013, 01:30:24 pm »
You need to work out the direction of your sprite to the light and then pick a sprite appropriately.
Work out the direction in angles by

Vector3 dir = lightPos  - carPos;
Mathf.Atan( dir.y, dir.x ) * Mathf.Rad2Deg; // what you use here depends on what direction is "forward" to your sprite. Normally the sprite is on the XY plane, so I'm just using XY there.

Now that you have a direction in angles, its just a matter of picking the correct sprite.