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

Windows "physics_apply_force" doesn't work for 0 density object

P

Pylon

Guest
I have an object with 3 fixtures (don't know if that counts).
It has physics enabled and 0 density because I need it to stay still on screen.
I'm trying to use "physics_apply_force(x, y, 0, -15)" on "Left pressed" on it. Doesn't budge.

Is this the way things should work or am I doing something wrong? Thanks.

Edit:
I'm actually trying to drag the object around with the mouse. Also I need this object to collide with others.
The code I'm using now is this:
=============================
Create event:

grab = false;
xx = 0;
yy = 0;
_________
Step event:

if(grab==true)
{
phy_linear_velocity_x=mouse_x+xx;
phy_linear_velocity_y=mouse_y+yy;
}
_______________
Left Pressed event:

grab = true;
xx=phy_position_x-mouse_x;
yy=phy_position_y-mouse_y;
________________
Left Released event:

grab = false;
==============================

The problem with "phy_linear_velocity_x" is that once I click on the object it just goes in one direction without stopping.
Before this, I tried "phy_position_x" instead, and it works, but if I move the object too fast the other objects clip through it sometimes (like the calculations can't keep up or something).
Then, I tried "physics_apply_force" because I thought they won't clip through anymore, but that doesn't move the object at all.

I apologize, I should have been clearer from the beginning.
 
Last edited by a moderator:

xDGameStudios

GameMaker Staff
GameMaker Dev.
I think that’s it! You want it to stay still so setting density to zero will make it “still” (or by other words unmovable).
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You really should read the documentation...

  • Density: A material's density is defined as its mass per unit volume. It is, essentially, a measurement of how tightly matter is crammed together. If you wish your fixture to be static (ie: immovable) then the density should be set to 0, essentially making it infinitely dense. Kinematic objects that move with constant velocity and are not physically affected by collisions are also defined using a density of 0.
http://docs2.yoyogames.com/index.ht...g/4_gml_reference/physics/fixtures/index.html
 
F

Flab

Guest
I seriously dislike the density value (rather than mass) . Using 0 mass/density objects is a very common "trick" in physics engines for static or immovable objects without any effort.

Imagine this, for instance (it applies to density, rather than mass too, as they are roughly interchangeable and related terms):
acceleration = force / mass; if mass is zero...

If you want it to move, you should alter velocity directly, either with an impulse or I dunno what GMS uses for that.

Edit:
In fact, most implementations involving impulses also typically use/rely on mass, so probably not with that. So, whatever methods are available for altering acceleration, velocity and position (depending on what you need), rather than force and momentum.
 
Last edited by a moderator:

Bingdom

Googledom
P

Pylon

Guest
Your variables are wrong
Code:
//Move the object
phy_speed_x = mouse_x-x;
phy_speed_y = mouse_y-y;
For all physics variables
https://docs.yoyogames.com/source/dadiospice/002_reference/physics/physics variables/index.html

To know why that variable is incorrect (unless you want it to smoothen), take another look at the manual:
http://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/physics/physics variables/phy_linear_velocity_x.html
It's in seconds, not pixel per step
Thanks. Tried it. It works, but the center of the object always jumps at the mouse position and I need the mouse to grab the object from whatever point on it.
Also once I click, even if I release the mouse, the object will still follow it. I tried with "Left Down" event but same result.
I looked at all the variables and I don't think any of them can do what I want. If I use "physics_apply_force" or "physics_apply_impulse" I can't move the object cuz it has 0 density.
What I need is to change the position of the object along with the position of the mouse. You would think it'd be easy. Again, if I use "phy_position" I get glitches with the other objects. There might actually be no way to do this properly.
 
Top