2D Toolkit Forum

2D Toolkit => Support => Topic started by: Der_Kevin on October 23, 2013, 03:16:12 pm

Title: Sprites always Rotate after use shadow-offset-script
Post by: Der_Kevin on October 23, 2013, 03:16:12 pm
Hey 2D Toolkit guys!
Iam having a weird problem. I am trying to "fake" a 2d shadow with a little offset script
Code: [Select]
var car : Transform;
var offset : Vector3;
function Update(){
   transform.position = car.position+offset;
   transform.rotation = car.rotation;
}

so i created a shadow sprite, placed it into my scene put the script on it and pressed play. but suddenly the shadow snapped back to to 0°. I changed it to 90° on the X axis cause I am doing a top down game and the 2dtoolkit usually place the sprites horizontal cause i guess its mainly made for platform games. Which is also a little bit nasty cause i have to rotate the sprite every time i place them to 90° but jeah, i can live with that.#

when I am disabling the Script the shadow stays on the right axis. but as soon as i enable it it snaps back to zero.

here is an image that show you the problem:
(http://img208.imageshack.us/img208/5150/l75k.jpg)

thanks!
Title: Re: Sprites always Rotate after use shadow-offset-script
Post by: unikronsoftware on October 23, 2013, 08:21:13 pm
It looks like its just doing exactly what you're telling it to. You're setting the transform to be the same as the car, which happens to be Z-forward. You'll need to rotate the car rotation matrix. Eg. set transform.rotation = car.rotation; You could transform.rotate(...) after that, or simply multiply the quaternion by a Quaternion.Euler(90, 0, 0);
Title: Re: Sprites always Rotate after use shadow-offset-script
Post by: Der_Kevin on October 24, 2013, 02:50:03 pm
Ah, jeah, that make sense. thanks :)
so, if someone have the same problem in the future, this helped:

Code: [Select]
var car : Transform;
var offset : Vector3;

function Update(){
   transform.position = car.position+offset;
   transform.rotation = car.rotation;
   transform.rotation = Quaternion.Euler(90, 0, 0);
}