Jump to content


Photo

Physics Stuff


  • Please log in to reply
17 replies to this topic

#1 SamBaylus

SamBaylus

    GMC Member

  • GMC Member
  • 89 posts

Posted 24 May 2012 - 06:55 PM

I'm going to make this thread a topic for my questions regarding Physics, since I seem to have a lot of them but I'd rather not clutter up the board with them.

// NEW QUESTIONS!
2.
When an object uses physics, it seems as though certain events no longer work correctly;
For instance, when an object moves from its starting position, mouse events still are only registered at the object's starting position. If I have a "left button pressed" mouse event, I can ALWAYS click where, for instance, the ball was at the start of the game to access the event. The event does not register when I click on the actual ball.

How should I be handling "when I click an object with the mouse" events properly using physics?

// OLDER QUESTIONS
1.
When creating a fixture, I realize that the shape cannot be concave.
However, for a game like pinball, when the ball is typically shot into the playing area for the first time, it follows an arch along the border into the area.
Is there a way to replicate this, or a good substitute? I'd think that a pinball game would be a great way to get familiar with the physics engine, but it seems a bit weird to have no work-arounds for making an arch-shaped fixture.
//

Thank you!

Edited by SamBaylus, 25 May 2012 - 04:42 AM.

  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 24 May 2012 - 07:33 PM

you could just not have physics happening at the start(using a path and an object) so its always the same

they plan to include concave fixtures this will come intime, i look forward to it like all my ideas require them...
  • 0

#3 scurvycapn

scurvycapn

    GMC Member

  • GMC Member
  • 171 posts
  • Version:GM:Studio

Posted 24 May 2012 - 07:56 PM

you could just not have physics happening at the start(using a path and an object) so its always the same

they plan to include concave fixtures this will come intime, i look forward to it like all my ideas require them...

Are you sure about that? The inability to use concave fixtures is a box2d limitation, not a GameMaker limitation. Just like the maximum of eight vertices per fixture is part of the box2d code as well. One can get around these limitations by using multiple fixtures, and maybe YoYo could help developers out by allowing you to define the a shape and then splitting it into multiple fixtures that follow the limitations for you, but I haven't heard anything along those lines.
  • 0

#4 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 24 May 2012 - 08:05 PM

YoYo could help developers out by allowing you to define the a shape and then splitting it into multiple fixtures that follow the limitations for you


im not sure about anything, yoyo changes there mind alot, but it was in the beta help file mentioning the inabillity and plans. but i expect if they do do it they most likely would do it the way you said.

i hope it will happen
  • 0

#5 thescotster19

thescotster19

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 24 May 2012 - 08:08 PM


you could just not have physics happening at the start(using a path and an object) so its always the same

they plan to include concave fixtures this will come intime, i look forward to it like all my ideas require them...

Are you sure about that? The inability to use concave fixtures is a box2d limitation, not a GameMaker limitation. Just like the maximum of eight vertices per fixture is part of the box2d code as well. One can get around these limitations by using multiple fixtures, and maybe YoYo could help developers out by allowing you to define the a shape and then splitting it into multiple fixtures that follow the limitations for you, but I haven't heard anything along those lines.


Two options I can see:

1. Multiple physical box type objects at different angles. Wouldn't be that good I think, quite bouncy.

2. Attach the ball to another object at the centre of the "circle" via a joint. Set the joint such that the ball can move towards it but cannot go beyond a fixed range. On the interior edge of the ball path put another circular physical object, which is also centred on the joint object. In fact they could be one and the same I expect. After a certain point, detach the joint, and set the ball to no longer collide with the circle object.

Like this:

Posted Image

Edited by thescotster19, 24 May 2012 - 08:10 PM.

  • 0

#6 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16792 posts
  • Version:GM:Studio

Posted 24 May 2012 - 08:10 PM

Unless I am mistaken... You CAN add two (or more) Fixtures to one object. So you can combine fixtures to create a concave effect.
  • 0

#7 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 24 May 2012 - 08:14 PM

you can add multiple fixtures BUT. to achieve a big curved surface like this one would require many, and he already plans to have a whole board of physics objects and yoyo says to try to use alot less than 50(this may be 50 that are moving dono).
  • 0

#8 thescotster19

thescotster19

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 24 May 2012 - 08:56 PM

you can add multiple fixtures BUT. to achieve a big curved surface like this one would require many, and he already plans to have a whole board of physics objects and yoyo says to try to use alot less than 50(this may be 50 that are moving dono).


I have had a test with more than 800 32x32 boxes moving dynamically before the framerate drops below 60fps. Seems reasonably powerful, but it was not a scientific test.
  • 0

#9 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16792 posts
  • Version:GM:Studio

Posted 24 May 2012 - 09:03 PM

With just three or four fixtures you can approximate a curve sufficiently that with actual curved graphics and the speed the ball moves the eye will be fooled... and if the instance is static rather than kinematic then there is much less work for the physics so it should be okay use possible more.
  • 0

#10 SamBaylus

SamBaylus

    GMC Member

  • GMC Member
  • 89 posts

Posted 24 May 2012 - 09:24 PM

All interesting ideas, I'll have to try them all out and let everyone know what happens.

I'm also having some trouble finding my way around the Physics engine as a whole, using GM:Studio. Has anyone made tutorials on Physics and Joints in GM:Studio yet? If not, I may have to brute force my way through it and post some tutorials...
  • 0

#11 thescotster19

thescotster19

    GMC Member

  • GMC Member
  • 236 posts
  • Version:GM:Studio

Posted 24 May 2012 - 09:32 PM

All interesting ideas, I'll have to try them all out and let everyone know what happens.

I'm also having some trouble finding my way around the Physics engine as a whole, using GM:Studio. Has anyone made tutorials on Physics and Joints in GM:Studio yet? If not, I may have to brute force my way through it and post some tutorials...


There is actually a tutorial with the software that is pretty useful to start (asteroids game). Make sure you use the help file as a reference, most things are covered.

I have been brute-forcing it and it is very good once you work things out.
  • 0

#12 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16792 posts
  • Version:GM:Studio

Posted 24 May 2012 - 09:44 PM

The tutorial is very basic, but covers the most important thing which is "the physics world is DIFFIRENT!". Honestly, thatīs the most important thing you can realise... The coordinate system is diffirent (0,0 is still the top left, but now +y is UP) the angles are clockwise (in standard GM they are anti-clockwise), gravity and forces are calculated as vectors, and in general none of the standard GM norm instance variables work (speed, gravity, friction,... even x and y!!!). So, once you start to actually think in those terms it's pretty easy to use...

Oh, and read the manual dos and donts (References >>> Physics) as there are a few things that you shouldn't do (like make a wall of 50 physics objects. Better to make one large long object!).
  • 0

#13 SamBaylus

SamBaylus

    GMC Member

  • GMC Member
  • 89 posts

Posted 25 May 2012 - 04:43 AM

New question, so I'd like to bump, please! Read the first post.
  • 0

#14 SLarouche

SLarouche

    GMC Member

  • GMC Member
  • 91 posts
  • Version:GM:Studio

Posted 25 May 2012 - 05:59 AM

// NEW QUESTIONS!
2.
When an object uses physics, it seems as though certain events no longer work correctly;
For instance, when an object moves from its starting position, mouse events still are only registered at the object's starting position. If I have a "left button pressed" mouse event, I can ALWAYS click where, for instance, the ball was at the start of the game to access the event. The event does not register when I click on the actual ball.

How should I be handling "when I click an object with the mouse" events properly using physics?


Might it be because physic objects uses "phy_position_x" and "phy_position_y" and not the standard... stuff?

Smon

Edited by SLarouche, 25 May 2012 - 06:00 AM.

  • 0

#15 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1407 posts
  • Version:Unknown

Posted 25 May 2012 - 08:19 AM

I have just checked this and this definitely works properly - the mouse event definitely is working on physics objects.

If you think you have found a bug though - please file a bug Help -> report a bug.

Russell
  • 0

#16 SamBaylus

SamBaylus

    GMC Member

  • GMC Member
  • 89 posts

Posted 26 May 2012 - 06:35 AM

MM, I believe it's a bug. I can re-create it many times over, and I can easily fix it. I just have a basic room with gravity, a floor, and a box. The box falls from gravity. When I click on the box, I send it to a random x/y on the map. It then re-appears somewhere, then falls back to the floor. HOwever, once the box is in-air from a recent click, I can continuously click on the spot where the box used to be, and it'll continue being placed randomly around the room as if I had clicked it. However, if I allow the box to land, that becomes the new "hotspot" for the mouse clicks.

I can solve the problem by adding in the step event:
x = phy_position_x;
y = phy_position_y;

This allows me to be able to click on the object mid-air, and not allow it to register an "on left button" mouse event when the box is no longer in that position.
  • 0

#17 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16792 posts
  • Version:GM:Studio

Posted 26 May 2012 - 07:04 AM

You have to understand that physics is not the same as traditional GM stuff... So, in the real world, you can`t just "teleport" something from one spot to another and expect it to behave as normal, nor can you do it in GM. In both the manual AND the tutorial included with GM it is made very clear that the internal variables no longer can be used as before. So yes, you SHOULD be referencing phy_position_x and phy_position_y instead of x and y anyway, the same as you reference phy_rotation and not image_angle, or phy_velocity_x and not hspeed...


However, I agree that the mask for an instance should move with the instance (even when you break the laws of physics, as in games it's what you DO!) so please export your testfile as a gmz and post a bug. Posted Image
  • 0

#18 SamBaylus

SamBaylus

    GMC Member

  • GMC Member
  • 89 posts

Posted 26 May 2012 - 07:19 AM

On a related note, you can also simply update the variables "x" and "y" to "phy_position_x" and "phy_position_y" respectively directly after changing an object's x/y and the masks will then work properly. You do not have to have them in the step event at all times... save some processes, will ya?!

Okay, I've also been trying to figure out how to make a simulated "mouse joint". I want to be able to pick up a box, move it around, fling it, etc. I tried some different joints, but nothing really is what I'm looking for. Doing some reading online I hear I should be looking for a "mouse joint". Any plans on adding this? If not, how can I go about achieving a "pickup and throw" system with the mouse and my objects?

Thanks!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users