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

Weapon object/sprite plays upside down

pixeltroid

Member
ok, so basically I have a weapon object that is attached to the player when its called. I have made it so that the weapon points in the direction the player is facing/

What happens is that the weapon object gets created at a specific point in relation to players position -- whether he's facing left and right for standing, crouching, jumping or pointing up. When the weapon is created, it plays a short animation of around 5 frames and then self destructs. Works fine....almost.

But there is one problem that has been bugging me and I dont know how to fix it.

When I point up and use the weapon, the sprite appears and works just fine. BUT....if I turn around while the sprite is playing, the sprite/object changes its orientation for some reason -- and I cant figure out whats causing it.

Here's what the problem looks like:

pointup.jpg
This is when I'm pointing up. Works great.

pointup2.jpg
This is when I turn around while the weapon sprite is playing. The object/sprite appears to be flipped over vertical.

Here's the code of the script that's called when I point up and press the button to use that weapon.

Code:
if image_xscale > 0 {
{
var fl = instance_create(x-5 , y-40, obj_flamethrower); //creates weapon object
fl.direction = 90
fl.image_angle = 90
fl.speed = 0;
}
global.flame  -= 1
alarm[5]= 60
}

if image_xscale < 0 {
{
var fl = instance_create(x+5 , y-40, obj_flamethrower); //creates weapon object
fl.direction = 270
fl.image_angle = 270
fl.speed = 0;
}
global.flame  -= 1
alarm[5]= 60
}

//store variables for following
fl.owner = id;
fl.x_offset = 1*image_xscale;
fl.y_offset = -41*image_yscale;
I have this code in the weapon object's end step event:

Code:
if instance_exists(owner) {
image_xscale = owner.image_xscale;
x = owner.x + x_offset;
y = owner.y + y_offset;
}
How do I fix the issue?

Please let me know if you want to see more related code!

Any help would be greatly appreciated!
 
When you create it, you give it an image angle, but you then update its xscale in real time. You'll have to account for the image angle as well if you're going to do that.
 
You can do one of two things.

1) You stick to what you've done, and instead of flipping any scale in real time, you alter the direction and image angle like you did upon creation.
2) You set the direction and image angle the same for both directions, but you flip the y scale both in its creation and updates.
 

pixeltroid

Member
update: I got it to work.

I tweaked around with the code a little bit and made a few changes to the script, as shown in green


Code:
if image_xscale > 0 {
{
var fl = instance_create(x , y, obj_flamethrower); //creates weapon object
fl.direction = 90
fl.image_angle = 90
fl.speed = 0;
}
global.flame  -= 1
alarm[5]= 60
}

if image_xscale < 0 {
{
var fl = instance_create(x , y, obj_flamethrower); //creates weapon object
fl.direction = 270
fl.image_angle = 270
fl.speed = 0;
}
global.flame  -= 1
alarm[5]= 60
}

//store variables for following
fl.owner = id;
fl.x_offset = 1*image_xscale;
fl.y_offset = -32*image_yscale;
So basically, I just specified the offset in the last 2 lines.

Anyway, things like angles and rotations have always confused me since day 1 on Gamemaker! XD

Thanks to @BattleRifle BR55 and @MilesThatch for trying to help.
 
Top