Child Object Switching xscale (-1 and 1)

F

Fritter Critter

Guest
I have a parent object which works fine, and created a child object and changed nothing about its code or variables. When I place the child object in a room, it walks normally and then rapidly switches between being left-oriented and right-oriented, when the object would normally jump. The parent objects work just fine. How can the child object malfunction when I haven't changed anything about it? Thank you for your help in advance!
 

CloseRange

Member
there is always something that is being changed. Even if it's as small as the objects name (can't be the same). Sounds small but there is a lot that can mess up with just a change in an objects name.
Other things that can have an effect (perhaps not in your case but things to think about)
  • size of the sprites being used.
  • Using sprites at all.
  • inital starting position of the instances.
  • when/how it's being created
  • the code surrounding the create events (if you use instance_create)
  • the origin of the sprite used (that's a big one associated with orientation like your case)
  • any other exterior scripts that might reference your child object but not your parent.

MOD EDIT: Offensive language removed. Please do NOT use offensive language on these forums, nor try to bypass the swear-filter. Next time you'll get a warning and your account may be restricted.

MY EDIT: very confused. I don't remember having any offensive language :confused: nor does the post look any different than I remember. Sorry if I accidentally offended anyone maybe I was just tired and didn't notice, good day! :)
 
Last edited:

GMWolf

aka fel666
Code would be nice to help.
If you are compiling with YYC, have you tried clearing the cache? (Brush button).

And yes, the sprite size and origin might be the cause here, what happens if you use the same sprite?
 
F

Fritter Critter

Guest
  • Thank you for the suggestion to clear the cache but the problem is still happening...
  • I am also using the same sprite as parent object so there shouldn't be a size/origin problem that I can think of.
  • I looked for any reference to the parent object's name (oEnemy) throughout my code and it is never referenced. The only search that came up was the reference to oEnemyDead, which you can see in the code below.
  • I have included the code for my parent enemy object and a short video capture of the parent and child objects in the same scene. Let me know if anything else would be helpful.
  • In the video, you can see that the issue comes into play when my airborne enemy comes back in contact with the ground. I am new to GameMaker so any advice helps, thank you!

Begin Step Event:


if (hp <= 0)
{
with (instance_create_layer(x, y, layer, oEnemyDead))
{
direction = other.hitfrom;
hsp = lengthdir_x(3,direction);
vsp = lengthdir_y(3,direction)-4;
if (hsp!=0) image_xscale = (sign(hsp));
//image_yscale = other.size;
}
instance_destroy();

}


Step Event:


vsp = vsp + grv;

//Horizontal Collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x+sign(hsp);
}
hsp = -hsp;
}
x = x + hsp;

//Vertical Collision
if (place_meeting(x,vsp+y,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y+sign(vsp);
}
vsp = 0;
}
y = y + vsp;

// Periodic Jumping
jumpdelay = jumpdelay - 1;
if (jumpdelay < 0)
{
jumpdelay = 200;
vsp = -10;
}

//Animations
if (!place_meeting(x,y+1,oWall))
{
sprite_index = sEnemyA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = sEnemy;
}
else
{
sprite_index = sEnemyR;
}
}

image_xscale = (sign(hsp));
//image_yscale = size;


Draw Event:

draw_self()
if flash > 0
{
flash--;
shader_set(shWhite);
draw_self();
shader_reset()
}

 
Last edited by a moderator:

rytan451

Member
The line that's causing problems is:
Code:
// Step event
if (place_meeting(x+hsp,y,oWall)) {
    //...
    hsp = -hsp;
}
You're having problems with horizontal collision, I think. If the object is meeting a wall on both the left and right sides, it would end up switching between left and right once per frame, as displayed in the video.
 
Top