Hello everybody,
I just started experimenting with unity a few days ago.
I am currently trying to get a top-down engine running.
This is the current situation:
http://www.it-liebig.com/unity/Link/Link.html
Walk with W,A,S,D and attack with SPACE.
As you will see, the sword that is spawned when pressing SPACE will ignore the players direction.
I created a animation for the sword…which is the one you can see…but the animation ignores the rotation I assign it.
When the player spawns the objSword its done this way:
void checkAttack()
{
if (!this.isAttacking)
{
if (Input.GetKeyDown(KeyCode.Space))
{
this.isAttacking = true;
Invoke("stopAttack",this.attackDuration);
if (this.weapon)
{
Quaternion rotate = Quaternion.identity;
if ((this.direction & eDirection.down) == eDirection.down)
rotate = new Quaternion(0f,0f,90f,0f);
else if ((this.direction & eDirection.up) == eDirection.up)
rotate = new Quaternion(0f,0f,270f,0f);
else if ((this.direction & eDirection.right) == eDirection.right)
rotate = new Quaternion(0f,0f,180f,0f);
else if ((this.direction & eDirection.left) == eDirection.left)
rotate = new Quaternion(0f,0f,-0f,0f);
GameObject _sw = Instantiate(this.weapon,this.transform.position, rotate) as GameObject;
_sw.transform.rotation = rotate;
_sw.transform.animation.renderer.transform.rotation = rotate;
}
}
}
}
I am using a bitshifting enum to support multiple directions for walking.
So, I then spawn the objSword (_sw) and try to assign the rotation…but this is ignored.
Should the sword be a child of the player object?
Did I do something horrible wrong?
I think I am missing something important here…some fundamental understanding maybe.
Thanks in advance!
