• 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!

flipping projectiles

boy656

Member
how do i flip my projectiles depending on which direction im facing?

CODE/
key press X

var inst;
inst = instance_create_depth(x, y, -10000, objectBullet);
with (inst)
{
speed = other.shoot_speed;
direction = other.image_angle;
}

objectBullet step:

hspeed=30;

/CODE
 

Relic

Member
Just like you set the direction of the projectile by doing direction=other.image_angle, you can set the projectiles other properties like image_angle too.

Is this a top down game? image_angle=direction or image_angle=other.image_angle will do it (either works since you already set the bullet direction to be the player’s image angle)
 

SeraphSword

Member
Try image_angle = direction right after direction = other.image_angle
Assuming that your sprite is made pointing directly to the right, that should work. If not you'll have to adjust the angle by whatever you have it drawn like in your sprite.
 

boy656

Member
the code didn't work.

what i had wanted was for the projectile sprite to flip itself and go the opposite direction with the same speed, whenever facing left.
 

pipebkOT

Member
@boy656
if is the same project with the "fireballs" then you only need to have these


fireball create event

if global.facing="right"
{
image_xscale=1
hspeed=3
}
else
{
image_xscale =-1
hspeed=-3
}


alarm[0]=180 ///equals 3 secons of bouncing fireball
gravity=3


edited
 
Last edited:

SeraphSword

Member
Okay, so you want the bullet to flip-flop in either direction as your character turns?

Then just add the image_angle = direction code to the bullet's Step event instead. And place code for direction = other.image_angle above it.
 

pipebkOT

Member
what do you mean by that? the variable global.facing="right" ?


if is the same project I helped before, the variable global.facing="right" was already set in the player create event and is changing each time you press left or right
 
Last edited:

pipebkOT

Member
the bullets shoots?, only to the right? if so thats because you didn't set

the left and right events

player pressed right event

global.facing="right"




player pressed left event

global.facing="left"


you need to tell me what doesn't work specifically
 

TheouAegis

Member
Post all your code for your weapon. Post all your code for this projectile. Odds are you have code in the projectile, which you do not want in the projectile at all because the object that is creating the projectile is the one that is supposed to be setting all of the projectile's variables.
 

boy656

Member
objectIdle:

Create:

/// @description Movement variables
velocity_ = [0, 16];
gravity_ = 1.5;
jump_speed_ = 48;
max_velocity_ = [22, 42];
acceleration_ = 6.1;
shoot_speed = 40
// Get the tilemap id
var layer_id = layer_get_id("Collision");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);
global.facing="right";
can_shoot = true;
hspd = 0;
vspd = 0;
hspd_max = 3; // Max horizontal speed. We will flip this when moving left to -hspd_max
vspd_max = 6; // Max vertical speed. We will flip this when jumping to -vspd_max
accel = 0.2;
fric = 0.2;
grav = 0.4;
climb_max = 8; // The max distance we can climb for ascending and for descending

Step:

/// @description Movement logic
// Get the input
var key_right, key_left, key_jump, input_x, on_ground;
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(ord("Z"));
input_x = keyboard_check(vk_right) - keyboard_check(vk_left);
// Vector variables
var vector2_x = 0;
var vector2_y = 1;
// Horizontal movement
velocity_[vector2_x] = clamp(velocity_[vector2_x]+input_x, -max_velocity_[vector2_x], max_velocity_[vector2_x]);
// Friction
if input_x == 0 {
velocity_[vector2_x] = lerp(velocity_[vector2_x], 0, .2);
}
// Gravity
velocity_[vector2_y] += gravity_;
// Move and contact tiles
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);
// Jumping
on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
if (input_x != 0)
{
// Set sprite if you're on the ground
if (on_ground)
{
sprite_index = spriteRun;
}
// Face right or left
image_xscale = input_x;
}
else
{
// Set sprite if you're on the ground
if (on_ground)
{
sprite_index = sprite0;
}
// Slow down
}
// Jump
if (key_jump && on_ground)
{
sprite_index = sprite2;
velocity_[vector2_y] = -jump_speed_;
}
// Gravity
if (!on_ground)
{
// Set your sprite if you're falling
if (vspd > 0)
{
sprite_index = sprite2;
}
}

Alarm 0:

can_shoot = true;

if collide with object8:

game_restart();

Key Press X:

var inst;
inst = instance_create_depth(x, y, -10000, objectBullet);
with (inst)
{
speed = other.shoot_speed;
direction = other.image_angle;
image_angle = direction;
}

Key Press R:

game_restart();

objectBullet:

Create:

alarm[0]=750; ///equals 2 and half seconds of bouncing fireball
gravity=10.5;
velocity_ = [0, 16];
gravity_ = 1.5;
var layer_id = layer_get_id("Collision");
collision_tile_map_id_ = layer_tilemap_get_id(layer_id);

Step:

if place_free(x,y+1)
{
gravity=0.5;
}
var on_ground
move_and_contact_tiles(collision_tile_map_id_, 64, velocity_);
// Jumping
on_ground = tile_collide_at_points(collision_tile_map_id_, [bbox_left, bbox_bottom], [bbox_right-1, bbox_bottom]);
if on_ground
{
vspeed = -10;
}
if global.facing="right"
{
image_xscale=1
hspeed=3
}
else
{
image_xscale =-1
hspeed=-3
}

Alarm 0:

instance_destroy();
 

pipebkOT

Member
you need to also specify what's the problem with the code:

the bullet shoots? to the righ? and to the left?

does the sprite look good?
you want it to bounce? if so
it bounce correctly?
it flips when you shoot it to the left?
 

pipebkOT

Member
object bullet


if global.facing="right"
{
image_xscale=1
hspeed=3
}
else
{
image_xscale =-1
hspeed=-3
}

this code should be in the bullet CREATE event, not in the step or other events

basically you mixed all the code that the users in the forum gave you T-T, so there is code you don't need



in the player Pressed X event you only need this :


Code:
if global.facing="right"
{
instance_create_depth(x+10,y,10,objectBullet)
}
else
{
instance_create_depth(x-10,y,10,objectBullet) // left
}


ALSO you need to set the Player Right and left pressed events


player right pressed event

Code:
global.facing="right"



player left pressed event

Code:
global.facing="left"

if you don't do this the bullet will only face to the right
 
Last edited:

boy656

Member
i made the bullets small enough, and the flipped bullets when i turn left worked *mostly* perfectly. Thank you all for sticking beside this problem and fixing it.
 

pipebkOT

Member
how do you want the bullets to behave, do you want them to go in a straight line? or do you want it to fall to the floor and bounce in the floor like the mario fireballs?



the bullet sinks and stays there? or the bullet is bouncing on the floor?
 
Last edited:
Top