Legacy GM When should I use force and when impulse? (Physics)

T

TypicalHog

Guest
I'm making a space game and I'm using physics engine.
Should I use physics_apply_local_impulse or physics_apply_local_force for ship movement and bullet firing?
Currently I'm using force for ship and impulse for bullet.
Also, another quick question: Bullets are traveling slower than ship when going fast. How do I carry ship's velocity onto bullet?

Here's the code:

// Fire bullet
if keyboard_check(vk_space) {
if alarm[0] = -1 {
physics_apply_local_impulse(0, 0, -0.25, 0); // Recoil
bullet = instance_create(x + lengthdir_x(32, phy_rotation * -1), y + lengthdir_y(32, phy_rotation * -1), obj_bullet)
with (bullet) {
phy_bullet = true;
phy_rotation = other.phy_rotation;
physics_apply_local_impulse(0, 0, 100, 0);
alarm[0] = 300; // Bullet life (5 sec)
}
alarm[0] = 15; // Cooldown (0.25 sec)
}
}

P.S. Tabs got removed
 
A

Aura

Guest
*angelic voice*

http://docs.yoyogames.com/source/da...physics/forces/physics_apply_local_force.html

http://docs.yoyogames.com/source/da...ysics/forces/physics_apply_local_impulse.html

The Manual explains the difference between the two:

This is slightly different to a force in that when it is applied it will immediately affect the speed, and, potentially the torque (or "spin") of the object, particularly if the point chosen to apply the impulse has a vector that is not aligned with the centre of mass (note: the center of mass is not necessarily the same as the origin!).
 
A

Aura

Guest
*angelic voice*

http://docs.yoyogames.com/source/da...physics/forces/physics_apply_local_force.html

http://docs.yoyogames.com/source/da...ysics/forces/physics_apply_local_impulse.html

The Manual explains the difference between the two:

This is slightly different to a force in that when it is applied it will immediately affect the speed, and, potentially the torque (or "spin") of the object, particularly if the point chosen to apply the impulse has a vector that is not aligned with the centre of mass (note: the center of mass is not necessarily the same as the origin!).
 

Jezla

Member
I think you just need to increase the amount of impulse you're applying to the bullet; every thing else looks fine.
 
T

TypicalHog

Guest
Ok, what about this part? "Also, another quick question: Bullets are traveling slower than ship when going fast. How do I carry ship's velocity onto bullet?"
 
T

TypicalHog

Guest
I think you just need to increase the amount of impulse you're applying to the bullet; every thing else looks fine.
I can't, the highest speed objects can travel at is 20 (phy_speed).
When I think about it - that might be the cause of the problem above.
 

Jezla

Member
That's what I'm referring to. You're currently applying 100m/s impulse to the bullet. Increase it to 200 and see if that gets you what you want. The alternative is to manually set the bullet's velocity by using the phy_linear_velocity_x and _y variables.

Edit: just saw you're reply. You're probably right.
 

FrostyCat

Redemption Seeker
Why don't you pick up some basic physics facts before making your own call?

Basic fact #1: Force causes a chronic change in momentum, impulse causes an instantaneous change in momentum. If the ship's movement responds gradually to input then use force, if it moves and turns on a dime then use impulse. If the bullet's movement accelerates gradually then use force over time, if it starts right away then use impulse once.

Basic fact #2: Impulse is mass times change in velocity. If your instance has a high mass, more impulse is needed to achieve the same change in velocity. If you want the bullet to move faster from rest than the ship, multiply its mass by the velocity of the ship, with a small multiplier on top to make sure it's faster, that's the impulse you need.

Don't just turn on the physics system and think you are set. Learn the underlying theory or you will be wasting your time.
 
T

TypicalHog

Guest
Why don't you pick up some basic physics facts before making your own call?

Basic fact #1: Force causes a chronic change in momentum, impulse causes an instantaneous change in momentum. If the ship's movement responds gradually to input then use force, if it moves and turns on a dime then use impulse. If the bullet's movement accelerates gradually then use force over time, if it starts right away then use impulse once.

Basic fact #2: Impulse is mass times change in velocity. If your instance has a high mass, more impulse is needed to achieve the same change in velocity. If you want the bullet to move faster from rest than the ship, multiply its mass by the velocity of the ship, with a small multiplier on top to make sure it's faster, that's the impulse you need.

Don't just turn on the physics system and think you are set. Learn the underlying theory or you will be wasting your time.
Thank you, thats what i thought but wasn't sure.
 
Top