|
Hello all, First let me say I'm an animator by trade, so please excuse my code :) I have an issue with a simple 2d scroller I need help with. I have my hero and he has 2 types of attacks, a melee attack and a ranged attack. Enemies will spawn from behind and in front of the hero character. I use Vector3.Dot to get whether the enemy is behind or not. However when the character passes the origin these values flip. Also if I use the parent of the enemy and the gameObject (rotates to face character) my values are also flipped. If I use the parents of both objects, it seems to work fine but I can never turn to an attacker that is behind the character and deal damage. I am guessing that this might be a "space issue". The hero and enemies are setup like this Prefab EmptyGameObject CharacterRig I move the characters by moving the prefab object. I rotate the characters to look in either direction by rotating the EmptyGameObject. Have I gone about this the wrong way? I thought about using the character controller but I figured these guys were so simple, I dont need the ability to jump, that not using it would be the better option. It works when the character is in negative x, but when I cross into positive x, it doesn't work because the values have flipped. I have declared enemy as a JavaScript array, and I populate it with game objects that have a tag of BadGuy. The variable myPar is the parent of the emptyGameobject for the hero. Here is my code for checking if an enemy is in front or behind.
Any help would be appreciated! Thanks! Alex
(comments are locked)
|

Well after some work and I am quite sure jerry rigging I have it working. I just have a check for the origin and handle the exception accordingly. I'm sure there is a better way but this works :)