Open zchaoz opened 11 years ago
Just use 'playerLeg.transform.forward' for the forward direction. Since the player's velocity doesn't indicate their view direction anyway, it's more correct.
EDIT: just to clarify, the player is currently the ONLY ENTITY that can walk backwards, so the 'velocity' method will work for all other agents.
Oh, and make sure you swap the x and z coordinates on that. I know it should be obvious by now, but confusion over that has been responsible for like 60% of our bugs so far...
Hell you can probably just use that method to determine the wolf's facing as well, that's how the eyes do it.
Ok, to determine how much the wolf is looking at the player:
PlayerLegs playerLeg = obj.getObject().GetComponent
Vector2 wolfFacing = new Vector2(myBrain.transform.forward.x, myBrain.transform.forward.z);
float dot = Vector2.Dot(wolfFacing, playerPos - wolfPos);
So, I can use the above code to calculate which direction the player is facing right? Ex:
Vector2 playerFacing = new Vector2(x, z); float dot = Vector2.Dot(playerFacing, playerPos - wolfPost);
Does the difference in order between PlayerPos and WolfPost make any possible change to the result? for example if I leave them like (playerPos - wolfPost) or (wolfPost - playerPos).
nvm, fixed. Adding machine learning now
Title says it all.
Do you know another way to check if player is looking at the wolf? The code I'm using now is
PlayerLegs playerLeg = (PlayerLegs)obj.getObject().GetComponent();
Vector2 playerPos = playerLeg.getPosition();
Vector2 wolfPos = myBrain.legs.getPosition();
Vector2 WolfVelocity = myBrain.legs.getVelocity();
float dot = Vector2.Dot(WolfVelocity, playerPos - wolfPos);
if (dot > 0) { thereIsShepherd = true; }
It's not OK, especially the wolf is not moving i.e. its Velocity = (0,0).