|
Hello everyone. I have an enemy who moves back and forth and when the player is within range, the enemy stops, looks at the Player, and begins to shoot. It's very simple, but the shooting is off. I can't figure what I did wrong, but when the enemy shoots, he shoots towards the enemy, but at a 45 degree angle, so not at him really, just in his direction. If I go onto the other side of the enemy (it's a 2d sidescroller), then the enemy doesn't even shoot towards me on the other side. He just keeps shooting along the previous path. The enemy turns to face the Player if the players in range. Here's where I find out the direction: and here's my shoot function that gets called: Thank you for any help you guys can give.
(comments are locked)
|

Any one have any helpful information?
I'm sure it's a simple solution.
What does the script that moves the bullet look like? If you look in scene view is the blue arrow pointing at the player? What does the code that sets rotation look like?
Well, my sidescroller is working on the y and x axis, and my character and the bullet line up perfectly on the x-axis. Origianly I instantiated the bullet this way:
var instantiatedbullet = Instantiate(bullet,transform.Find("EnemyBulletSpawn").position, Quaternion.Euler(direction.normalized));
I saw somewhere that someone had the above code for instantiating so I tried that with no success. I find "direction" by doing this:
direction = PlayerScript.pPos - transform.position;
My bullet move script is as follows:
var bulletMoveSpeed: int = 25; var lifetime: float = 0.8; var lx; var ly;
static var Hit = false;
function Update () {
}
function Awake(){
}
function OnTriggerEnter(other : Collider){
{ Hit = true; Destroy(gameObject); }
}
Well your original version should have been:
If direction is the difference between the two locations.