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

Legacy GM I can't control physics_apply_impulse

  • Thread starter Vampery Productions
  • Start date
V

Vampery Productions

Guest
Hey everyone :)

I'm trying to control the speed of a bullet, but I can't control it. I'm using physics_apply_impulse to fire it off.

Here's the code:

Code:
var ldx = lengthdir_x(25,-other.phy_rotation)
var ldy = lengthdir_y(25,-other.phy_rotation)

var b = instance_create(x + ldx,y + ldy,obj_bullet)

with (b)
{
    phy_rotation = other.phy_rotation;
    owner = other.id
    phy_fixed_rotation = true
   
    var ldx2 = lengthdir_x(11,-other.phy_rotation)
    var ldy2 = lengthdir_y(11,-other.phy_rotation)
    physics_apply_impulse(x,y,ldx2,ldy2)
}
I'm trying to speed up the bullet, because right now, it's way too slow. How can I do this?
Thanks for reading! :)
 
J

Jaqueta

Guest
Just put that on the Creation code for the bullet.

phy_bullet=true

Description from Documentation
This variable defines whether or not the instance is extremely fast moving (for example a bullet). The default value is false but if set to true this tells GameMaker: Studio that the instance will be moving at such high speeds that it will require more expensive collision detection to ensure it doesn't pass through other instances undetected.
 
V

Vampery Productions

Guest
I'm afraid this isn't changing the speed, however it is good to know. Still need the speed changed though :)
 

FrostyCat

Redemption Seeker
Let me guess: You copied this off some random example without understanding it? Stop that.

The magnitude of the impulse is clearly the 11, make it bigger and it'll start faster. If you want better control over the resulting velocity, multiply the wanted velocity by phy_mass (J=mΔv).
 
V

Vampery Productions

Guest
I've tried to change the 11 to many different numbers. Both lower and extreme high, but there seems to be a limit to the maximum speed.
I tried to experiment with this physics_apply_impulse(x,y,1000000,1000000) and it doesn't change anything -except for the direction of the impulse of course.
Any clues why?
 

Jezla

Member
From the manual:
To prevent instabilities in the physical simulation Box2D constrains to upper limits the amount a body may rotate and translate within a single update. The apparent limitations will vary according to the accuracy of the physical simulation in accordance with the number of updates and update speed of the physics world, and also in accordance with the physics world scaling. This means that (for example) if you have a world update speed of 60, the maximum movement speed would be 20.
 
V

Vampery Productions

Guest
Okay, thank you all very much. I think I have to do this another way, but thank you all for helping! :)
 
Another thing you can do to increase the max speed of a physics room is to change the "Pixels To Meters" setting in the room physics settings tab. For example, if I make it half of its current value, the max physics speed is doubled. Note: This will affect the mass of all physics objects, and I believe it will have a negative impact on the accuracy of the simulation (I'm not 100% sure about that, it has never made a big difference in the accuracy of the simulation to me).
 
Top