About physics ... monster spinning and moving weirdly

Fabseven

Member
Hello there,
I am currently experiencing the physics system of GameMaker and i am encountering some problems.

The game is a "hero defense" , you have to shoot at waves of monsters with your heros... ok good.

I have an "explosing arrow" witch make an explosion making mobs flying if enough force.

Screen : mob moving
upload_2017-12-23_22-13-7.png

mob hitted by explosion arrow bombs :
sprite is spinning (great !)
upload_2017-12-23_22-14-41.png

after this the mob is moving like :

upload_2017-12-23_22-16-32.png

I tryed forcing phy_rotation to 0 when landing butttt if the landing speed is too great the mob is going trougth the ground and then "die" because going out of the screen.

So how can i manage to make the mob going back on his feets to move normaly again ?

Second question :
How can i make an ennemy fly ? Tried with phy_position_y = phy_position_yprevious but it seem to take a lot of CPU when multiples flying mob in the game ...
 
I

icuurd12b42

Guest
you can increase the angular damping to an obscene value...
you can set the angular momentum to 0 in the step if you want... ether setting it to 0 or multiplying is by .99. which would act like damping...
you can also gradually rotate the phy_angle so they land on their feet
 

Fabseven

Member
you can increase the angular damping to an obscene value...
you can set the angular momentum to 0 in the step if you want... ether setting it to 0 or multiplying is by .99. which would act like damping...
you can also gradually rotate the phy_angle so they land on their feet
thans for your advice,

Setting angular damping to 99 is working but the monster is not spining anymore (but at least he his on his feets when landing)
Tryied to gradually rotation the phy_rotation (phy_angle doesnot exist ?) BUTTTTT it's weird... most of the time the monster is flying when you do this as if you apply a big impulse... so in the end it doesnot work !
Code:
if( fly == false)
{
    if(alarm[10] == 0)
    {
        if(phy_rotation != 0)
        {   
   
            alarm[10] = 1
            show_debug_message("resetting phy_rotation")
            phy_rotation = clamp(phy_rotation--,0,360)
        }   
       
    }

}
alarm[10] is first setted to 30 in collision with obj_floor.
Bug ?
 
I

icuurd12b42

Guest
phy_rotation += clamp(angle_difference(phy_rotation,0).-5,5)

this can run each step without an if.... I maybe have reversed to arguments in angle_difference

you can reset the angular damping to allow free turning and use

phy_angular_velocity *=.99;

so... these 2 lines at top the step event of your ais
phy_rotation += clamp(angle_difference(phy_rotation,0).-5,5)
phy_angular_velocity *=.99;

this should allow blasting them and have them rotate and look like they, while in the air or the ground, are trying to fall back on their feet.
 

Fabseven

Member
phy_rotation += clamp(angle_difference(phy_rotation,0).-5,5)

this can run each step without an if.... I maybe have reversed to arguments in angle_difference

you can reset the angular damping to allow free turning and use

phy_angular_velocity *=.99;

so... these 2 lines at top the step event of your ais
phy_rotation += clamp(angle_difference(phy_rotation,0).-5,5)
phy_angular_velocity *=.99;

this should allow blasting them and have them rotate and look like they, while in the air or the ground, are trying to fall back on their feet.
First of all, thanks for you answer it's really helping (still have an hard time with physics)
Working fine except the mob is going back on his head instead of his feets, fixed it like this :

Code:
phy_rotation += clamp(-angle_difference(phy_rotation,0),-5,5)
phy_angular_velocity *=.99;
So it's working 80% of the time, not working it's when the monster cannot turn back on is feets before landing
is there a reason for the mob not turning any more because the collision event with floor = "nothing" ? weird.... maybe it's not right to move by using phy_speed_x = spd ?

Code:
Information about object: obj_monster
Sprite: spr_m_skel_right
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_monster_ground
obj_monster_fly
Mask:
Physics
Start Awake: true
Is Kinematic: false
Is Sensor: false
Density: 2
Restitution: 0.1
Group: 0
Linear Damping: 0.1
Angular Damping: 0.1
Friction: 0.2
Shape: Box
Points:
(0, 0)
(28, 0)
(28, 32)
(0, 32)
Create Event:
execute code:

monster_id=noone
spd = 1
dir = "RIGHT"
hit_time=room_speed
hit_color=c_red
hit = false
fly = false



monster_hp = 100
monster_hp_max = 100
monster_hp_p = 100
monster_def = 1
monster_atk = 2
monster_xp  = 10
monster_gold= 5
monster_range=0
monster_melee=true
monster_ia = monster_ia.melee


spr_move_right = noone
spr_move_left  = noone
spr_atk_left   = noone
spr_atk_right  = noone

Alarm Event for alarm 11:
COMMENT: hit time
Step Event:
execute code:

///feet rotation
phy_rotation += clamp(-angle_difference(phy_rotation,0),-5,5)
phy_angular_velocity *=.99;

execute code:

///moving
if(alarm[11] == 0)
{
   hit=false
   alarm[11] = noone
}


if( hit == false)
{
  
   if( dir == "RIGHT")
   {
       phy_speed_x = spd
       sprite_index =   spr_move_right
   }  
   else
   {
       phy_speed_x = spd * -1
       sprite_index =   spr_move_left
   }
  
}

Collision Event with object obj_floor:
COMMENT: nothing
execute code:


Collision Event with object obj_arrow:
COMMENT: something
execute code:

/*alarm[11] = hit_time
hit=true*/


show_debug_message("arrow force when hit")
physics_apply_impulse(x,y, other.phy_speed_x * -1 , other.phy_speed_y * -1)

Draw Event:
execute code:

if(alarm[11] > 0)
{
   image_blend = c_red
}
else
{
   image_blend = c_white
}


draw_self()
draw_text(x,y-10, string(monster_hp))

if(monster_hp_p < 100)
{
   draw_healthbar(x,y,x+sprite_width,y+1,monster_hp_p,c_white,c_red,c_green,0,false,false)
}

draw_text(x,y,string(phy_rotation))
 
I

icuurd12b42

Guest
phy_rotation += clamp(-angle_difference(phy_rotation,0),-5,5)
should bring them back to their feet even when on the ground... perhaps the shape of the collision combined with the friction of both character and ground ... and with the ai motion is preventing the code from fully rotating...
 
Top