• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

need help with bullet direction and speed!

V

VaygrEmpire

Guest
situation:
1. when enemy spawns, it flies toward player's position (doesn't change its direction even if player moves).
2. if in certain range, enemy starts to shoot at player for a few seconds.
3. enemy's bullet should not follow the player. However, it should keep flying based on obj_enemy's direction.

problem:
1. enemy's bullet follows the player

so far I was able to narrow the problem down to this level:
===================
direction = point_direction(obj_enemy_bf109e_yellow.x, obj_enemy_bf109e_yellow.y, x, y);
===================
the results seem to be satisfying. When the bullet is created, its direction looks ok. The thing is, if I set speed for this....it always head to right side of the map.

"move towards point" drop box also doesn't improve the situation. I set it as:
==========
x: x
y: y
speed: 10
==========
and still the same thing happens. if I set it as:
==========
x: obj_enemy_bf109e_yellow.x
y: obj_enemy_bf109e_yellow.y
speed: 10
==========
it flies toward opposite direction of the attachment.

How do I make enemy to fire bullets straight based on its flying direction?

Thanks for any help in advance!
 

Attachments

A

Aura

Guest
What event are you using? If you're putting that in the Step event, the bullet instance would change direction every step. If you don't want the bullet instance to change its direction after being created, use the Create event instead.

Also, why are you setting its direction to:

Code:
direction = point_direction(obj_enemy_bf109e_yellow.x, obj_enemy_bf109e_yellow.y, x, y);
Is the enemy object controlling the position at which the bullet instance is to be created? Also, does doing this:

Code:
with (instance_create(x, y, obj_Bullet)) {
   direction = other.direction;
   speed = 10;
}
...in the enemy object to create the bullets not work? It should make the bullets go in the direction which it itself is moving in. It should also prevent the bullets from changing direction every step.
 
V

VaygrEmpire

Guest
What event are you using? If you're putting that in the Step event, the bullet instance would change direction every step. If you don't want the bullet instance to change its direction after being created, use the Create event instead.

Also, why are you setting its direction to:

Code:
direction = point_direction(obj_enemy_bf109e_yellow.x, obj_enemy_bf109e_yellow.y, x, y);
Is the enemy object controlling the position at which the bullet instance is to be created? Also, does doing this:

Code:
with (instance_create(x, y, obj_Bullet)) {
   direction = other.direction;
   speed = 10;
}
...in the enemy object to create the bullets not work? It should make the bullets go in the direction which it itself is moving in. It should also prevent the bullets from changing direction every step.
1. I'm using Create event in obj_enemy_bullet.

2. I think so. Enemy spawns off the map, flies toward the player, and if conditions are met (less than range 200 and obj_enemy.y is smaller than obj_player.y) it will start shooting for a second.

3. Tried to put it under enemy object create event. Doesn't work. With step event, however, does work.
Code:
if distance_to_object(obj_player) < 200 {
    if (enemyBulletCount > 0 && enemyYellow.y < (obj_player.y-30)) {enemyBulletCount -= 1;
    with (instance_create(x, y, obj_enemy_bullet)) {
        direction = other.direction;
        speed = 25;}
        }
}
I put your code under conditions in step event by obj_enemyYellow and it looks good. Shooting straight based on obj_enemy direction. ...except one tiny thing.


As you may see from the attachment 02, the bullet is...not angled per obj_enemy. I've been playing with image_angle with point_direction, but no luck...
 

Attachments

T

Tomard

Guest
Have the enemy create the instance and set the variables of the instance in the with statement.

Code:
bullet = instance_create(x, y, obj_enemy_bullet;
With (bullet)
{
direction = other.direction;
image_angle = direction;
speed = 25
}
 
V

VaygrEmpire

Guest
The problem hasn't been fixed (still fires to right side as soon as image_angle is inserted. I do use image_angle for obj_enemy spawn and facing the player, but since it is with (other instance), it shouldn't have problem, right?). I don't know what the problem is, so I took this to the sprite level and changed it to round circle which always works.

Just to clarify, I removed entire direction = point_direction() from the obj_enemy_bullet and yet it's somehow still working...Am I using it elsewhere? No. I may have to look into this again in the future.

1. obj_enemyYellow is a child of obj_enemy_die.
2. obj_enemy_die is about collisions and does not contain any direction.
3. I'm currently spawning multiple enemy objects using alarm event drop button in separate object. (obj_enemy_spawn)
4. obj_enemyYellow has a few variables set and this:
Code:
image_angle = point_direction(x, y, obj_player.x, obj_player.y);
(This is to face player)
in Create event. Within Create event, there's also "move towards" drop button. (to fly toward player)
5. And then in Step event of obj_enemyYellow, codes in replies above rest.

The only other place I'm using direction is obj_bullet which is for player. This one works fine. And I'm not even calling it in obj_enemyYellow.

Can someone explain how direction works? Documentation doesn't really help me a lot. What's the base degree? How does
Code:
direction = other.direction
change the direction of the bullet? is "other" as in "opposite side"?
 
Last edited by a moderator:
Top