Jump to content


Photo

Physics collisions


  • Please log in to reply
10 replies to this topic

#1 vann

vann

    GMC Member

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

Posted 24 April 2012 - 07:07 AM

The manual suggests that you can also define collisions using collision events (as opposed to seeting two fixtures in the same group).

1) I am wondering how to make two objects collide (and interact accordingly - like bounce) which arent in the same group through using a collision event - I can't seem to find a function to do this.

2) Is there a way use the collision events for collisions between objects with fixtures and objects without fixtures? Ortherwse whats a good way to test these? collision_circle etc. or place_meeting?
  • 0

#2 JAk HAk

JAk HAk

    sepius fidelis

  • New Member
  • 713 posts
  • Version:GM:HTML5

Posted 24 April 2012 - 06:49 PM

I haven't encountered #1 or a solution to it yet, but #2 is easy enough. Physics objects still retain their sprite masks, just like any other object, so you can use place_meeting() with them or any of those collision detection functions. Just be mindful to update image_angle to phy_rotation so that it uses the orientation that it looks like it has (physics objects update phy_rotation instead and use that to draw their orientation by default).
  • 0

#3 vann

vann

    GMC Member

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

Posted 25 April 2012 - 02:34 PM

JAk HA, thanks for that, I was using this method, but thought I should check in case I was missing something more obvious :)

As for number 1 then, anyone else care to comment? Is this supposed to be possible? The manual makes it sound so.

I guess I need a Box2d equivalent of move_bounce_solid() but for two objects with fixtures which are not in the same collision group.
  • 0

#4 vann

vann

    GMC Member

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

Posted 28 April 2012 - 04:33 PM

bump
  • 0

#5 vann

vann

    GMC Member

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

Posted 02 May 2012 - 09:34 AM

Anyone? Is this (1) just not possible at the moment?

Edited by vann, 02 May 2012 - 11:34 AM.

  • 0

#6 ChefDavid22

ChefDavid22

    No, YOU shut up!

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

Posted 02 May 2012 - 02:58 PM

Here is how I did it with my game here: http://www.eodongame...?ID=virustroids

Take a look at the game first to make sure that's the type of physics you are looking for. When you bounce into what I call the virus - both you and the virus float away from each other.

First off in the collision event:

while (place_meeting(x, y, other)) 
{ 
x -= lengthdir_x(1, direction); 
y -= lengthdir_y(1, direction); 
} 
move_bounce_all(true);

Then add the same thing in the collision even BUT make sure you click on the radio button "OTHER" at the top.

Then step 2:

My code only works if you are not holding down what ever button you coded in to make the player move forward. So what I did was add a variable called "cannotmove" set it 0 on creation then set it to 1 in this collision....

if cannotmove = 0
{
while (place_meeting(x, y, other)) 
{ 
x -= lengthdir_x(1, direction); 
y -= lengthdir_y(1, direction); 
} 
move_bounce_all(true);
cannotmove = 1;
alarm[0]=room_speed*1.5;
}

Then I made an alarm[0] that puts cannotmove = 0 after 1.5 seconds.

THEN in the code where I press "UP" to move forward I made sure to check first to see what the value of cannotmove is

if cannotmove = 0
{
speed = 1;
etc 
etc
}


I wouldnt say my code is perfect by any means but for my game and its theme it works fine enough for me.

Edited by ChefDavid22, 02 May 2012 - 03:00 PM.

  • 0

#7 mrsmes

mrsmes

    GMC Member

  • GMC Member
  • 972 posts
  • Version:Unknown

Posted 05 May 2012 - 05:13 AM

that reminds me there is this one thing that really annoys me in the beta version of game maker studio, it has the time line actions but not the functions.
Back on topic: if your trying to make it roll and bounce that could take some experimenting.
  • 0

#8 vann

vann

    GMC Member

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

Posted 06 May 2012 - 02:33 AM

ChefDavid22,

Thanks for you reply but this isn't what I am looking for, I am wondering how to envoke physics collisions from box2D in the collision event, specifically how to do this without having two objects in the same collision group.

In the manual the caption for the third image in the entry for physics_fixture_set_collision_group(fixture, group) says:

These balls belong to different collision groups and they collide based on their collision event


What I can't work out is how to make them collide and react accordingly (using the physics engine) in their collision event.

Are any of the devs able to help clarify this, seems noone else has needed this functionality?

Thanks for any further help
  • 0

#9 mrsmes

mrsmes

    GMC Member

  • GMC Member
  • 972 posts
  • Version:Unknown

Posted 06 May 2012 - 04:23 AM

i think it's so they can set a variable in the collision event to 1 and if the user clicks it the objects in the group with the variable set to one vanish or explode.
  • 0

#10 vann

vann

    GMC Member

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

Posted 16 May 2012 - 12:06 PM

I wouldn't get that it was limited to this from they way they have worded the manual. It says:

These balls belong to different collision groups and they collide based on their collision event


The picture which accompanies the third image specifically has a ball from collision group -2 colliding (ie, bouncing) with a ball from collision group 1.

Can someone please explain how to acheive this, or put me out of my misery and tell me its actually not possible (yet?)...

Thanks again.
  • 0

#11 Joeben123

Joeben123

    GMC Member

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

Posted 16 July 2012 - 02:59 AM

I have just encountered this problem and after combing the forums I couldn't find anything useful. There is nothing in the guide or the wiki that explains it either. I am pretty surprised no one else seems to have this problem. Is everyone just putting objects in the same collision group if they want them to collide with physics?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users