Jump to content


Photo

Useful Collision Handler Scripts


  • Please log in to reply
30 replies to this topic

#1 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 30 October 2009 - 04:52 AM

Here is a a set of scripts I have implemented and use in all my stuff. Hope you like them

https://onedrive.liv...45D1EA9168D!726

You can export the scripts from the file or merge the game...

Some of the scripts require some object variables, like m_Mass and m_RotSpeed which you add to image_angle in your step... Init Script for the variables and Step scrips included if you use angular stuff...

Upadates:
Added examples

Edited by icuurd12b42, 20 August 2014 - 09:24 AM.

  • 6

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#2 fredcobain

fredcobain

    GMC Member

  • GMC Member
  • 165 posts

Posted 30 October 2009 - 01:14 PM

Please, include examples.
=)
  • 0
I am an Posted Image in the GM Quiz!

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 30 October 2009 - 08:33 PM

Examples added. Added a few missing scripts too.

Edited by icuurd12b42, 30 October 2009 - 08:34 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#4 Jepie0

Jepie0

    GMC Member

  • GMC Member
  • 213 posts

Posted 05 November 2009 - 12:47 PM

Very impressive icuurd12b42 those are some very helpful scripts. The included rooms show of the possibility's but it would be nice if there was a player controlled example. For instance maybe have a room filled with odd shapes that initially have no momentum and then allow a oddly shaped player object to move about interacting with them. Also i noticed in the egg room that sometimes the objects would pass threw each other. Is it possibly because one of the eggs was colliding with 2 other eggs at the same time but only passing on momentum and moving away from 1?

Cheers, Jepie0
  • 0

#5 fredcobain

fredcobain

    GMC Member

  • GMC Member
  • 165 posts

Posted 05 November 2009 - 03:48 PM

Very nice!!!

I liked!!!

=)
  • 0
I am an Posted Image in the GM Quiz!

#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 05 November 2009 - 10:22 PM

noticed in the egg room that sometimes the objects would pass threw each other. Is it possibly because one of the eggs was colliding with 2 other eggs at the same time but only passing on momentum and moving away from 1?
Cheers, Jepie0


It happens when the collision cannot be resolved... It can happen many ways. Yes, if colliding with multiple objects, sometimes the result is Towards() returns false with the second pairing because the first pairing caused one of the object to move away from the third. Also, with rotation...

The default is to ignore the collision but you can call other basic collision when this happens, like moveaway to gradually fix this or collisionmoveaway...

A player... OK, Added...

Shove match with cars
Balls bounce off it with no effect on the player, same with eggs (I was too lazy to make player move with speed)
Shoved out of the way by solids

Added CollisionMoveAway fallback collision for balls and eggs

The point of these functions is you can tailor the collision calling various functions. No one function does it all. You try one or another or a combination until the collision result is respectable.

Edited by icuurd12b42, 05 November 2009 - 10:35 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#7 infamousDee

infamousDee

    GMC Member

  • New Member
  • 11 posts

Posted 07 September 2010 - 04:59 PM

Thanks a bunch. This is exactly what I need. How would I get SolidObj to act as a wall which BallObj would bounce against, instead of speeding along its perimeter? Keep in mind that I still need the collision with PlayerObj to function correctly while BallObj is pressed against the wall, so don't just suggest using the move_bounce_all() function. :P

Edited by infamousDee, 07 September 2010 - 07:13 PM.

  • 0

#8 Dendail

Dendail

    GMC Member

  • GMC Member
  • 344 posts

Posted 25 July 2011 - 08:54 PM

I apologize for resurrecting this topic but I'm not sure where else to post this.

I think this is an awesome example with great scripts but I have one issue I'm not sure how to fix. Probably because it's against the physics I'm guessing but I was wondering how I can make the object (preferably the ball or any of the objects for that matter) to keep a constant speed & not slow down often when it collides into another object.
  • 0

#9 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 July 2011 - 05:11 AM

I apologize for resurrecting this topic but I'm not sure where else to post this.

I think this is an awesome example with great scripts but I have one issue I'm not sure how to fix. Probably because it's against the physics I'm guessing but I was wondering how I can make the object (preferably the ball or any of the objects for that matter) to keep a constant speed & not slow down often when it collides into another object.

put a max on your speed in the step event
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#10 Dendail

Dendail

    GMC Member

  • GMC Member
  • 344 posts

Posted 31 July 2011 - 04:52 PM

Sorry for the late reply but thank you very much. I ended up figuring it out later that night but Ty :)
  • 0

#11 Desert Dog

Desert Dog

    GMC Member

  • GMC Elder
  • 6409 posts
  • Version:Unknown

Posted 11 August 2011 - 09:23 PM

These are absolutely brilliant, and need far more attention on these forums than they're getting. Great work!
  • 0
HTML5 games for mobile:
HexDogs Bugz Burn! Captain George Golfing Block Memory

Games for Androids
*NEW* Word Dog - Published by Dangerous_Dave


Code: General Array Functions - GM-S friendly. sorting, shuffling. Includes a quicksort.
Use the quicksort to sort ds_lists 10-18 times faster than ds_list_sort()!

#12 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 25708 posts
  • Version:GM:Studio

Posted 11 August 2011 - 09:28 PM

These are absolutely brilliant, and need far more attention on these forums than they're getting. Great work!


Oh they get attention, just not posts! I link to these all the time as they are truly great for many, many things...
  • 0

U1FVsm3.png

40799.png


#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 03 April 2014 - 11:03 PM

in this case m_Mass is calculated in MassInit(). it's actual using the area of the sprite or the distance from upper left to lower right if I recall. it has to be a value greater than 0

in other setup I've modified the m_Mass after the MassInit call to be a most 1 and lower, like .1 in the case of a walking player vs zombies. so I can push according to strength. as for ships and cars, the method in the MassInit should be sufficient for out the box setup based on the sprite

I would not try to compare it to anything as the physics is completely fake. I would keep in mind that the greater the m_Mass difference between the 2 objects involved the greater the shove, the greater the push and the greater the rotation exchange.
  • 1

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#14 Ruub

Ruub

    Finn The Human

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

Posted 08 April 2014 - 09:49 PM

Works really sweet, though have to dive to really get things. D: +1


  • 0

#15 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 13 April 2014 - 02:46 AM

for say a bullet that hits a position at speed with mass
///add_force_xysdm (id,x,y,speed,direction,mass)
with(argument0)
{
var a;
a = angle_difference(point_direction(argument1-lengthdir_x(argument3,argument4),argument2-lengthdir_y(argument3,argument4),x-hspeed,y-vspeed),point_direction(argument1,argument2,x,y))
m_RotSpeed-=a*argument5/(m_Mass);
motion_add(argument4, argument3*argument5/m_Mass)
}

  • 1

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#16 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 13 April 2014 - 07:59 PM

Look at RotationInit()
m_RotSpeed is the speed and direction of the rotation +=angle per step
m_RotFriction = .99; //1 is no friction, 0 is full friction

x,y above is where it hits

I realise the code is a little wrong as it should make it spin more and add less velocity when the x,y is closer to the edges and the direction of both involved make an impact direction more perpendicular to the centre... and invert that statement the closer to the centre. again this is fakery so don't count on accuracy of the physics.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#17 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 25 April 2014 - 09:19 PM

Are you not calling if(Towards()) CollisionBalls()?


  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#18 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 April 2014 - 02:16 AM

maybe one of the if() condition is failing to return true when it should?


  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#19 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 April 2014 - 07:43 PM

if Towards() is not working then I think you forget to set the sprite origins centered


  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#20 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 27 April 2014 - 04:24 AM

No sure of the teleporting. There is a reason why I check if it just collided and moving towards for the ball collision. else you get weird things happening if you are inside and moving away from each other... I dont know if the teleporting is from the velocity transfer or from the moveaway... I may have a bug in it
 
The rotation transfer depends on mass and the speed of the collision and the rotation speed
 
JustHitR() is also a little finiky. if your stuff is generally round, you should set the round mask for the sprite and just use JustHit()

Edited by icuurd12b42, 27 April 2014 - 04:25 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#21 Dhiyananth

Dhiyananth

    GMC Member

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

Posted 10 July 2014 - 05:15 AM

Here is a a set of scripts I have implemented and use in all my stuff. Hope you like them

Download CollisionHandlers.gmk

You can export the scripts from the file or merge the game...

Some of the scripts require some object variables, like m_Mass and m_RotSpeed which you add to image_angle in your step... Init Script for the variables and Step scrips included if you use angular stuff...

Upadates:
Added examples

 

 

I tried to open the CollisionHandlers.gmk file in my Game Maker Studio,but it shows me some error and opening the project with only sprites included...can you check that...?


  • 0

#22 tafkam

tafkam

    GMC Member

  • New Member
  • 2 posts
  • Version:GM:Studio

Posted 19 August 2014 - 04:06 PM

So these scripts seem like something I could REALLY use...unfortunately it keeps saying it's 'corrupted' when I try to import them.

I'm using Studio (Free Edition) 1.3.1347

Anyhelp with this would really be appreciated.

 

6wn3mB0.png?1


  • 0

#23 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 20 August 2014 - 09:25 AM

So these scripts seem like something I could REALLY use...unfortunately it keeps saying it's 'corrupted' when I try to import them.

I'm using Studio (Free Edition) 1.3.1347

Anyhelp with this would really be appreciated.
 
6wn3mB0.png?1


https://onedrive.liv...45D1EA9168D!726

gmk (GM8), gml and gmz
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#24 tafkam

tafkam

    GMC Member

  • New Member
  • 2 posts
  • Version:GM:Studio

Posted 22 August 2014 - 08:31 PM

Yeah, I JUST realized my error right before seeing your response.
I only downloaded the gmk from the response not the zip from your original post. Total fail on my part. Thanks so much for responding.


  • 0

#25 Legendary_Agent

Legendary_Agent

    GMC Member

  • GMC Member
  • 369 posts

Posted 25 July 2015 - 09:42 AM

Excelent collision script and just what ive been looking for, i had tried and made my own collision script but then realized theres so much work that it still needed that i ended up postphone it and later given up so i could focus my time on other more important parts of  the game... untill i found this, I am sorry for this question which might seem dumb, but do we have the right to use it for commercial games too for free?


  • 0

#26 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 July 2015 - 01:59 AM

It's fine. you may credit me if you was to, I know I'm always looking for names to add in the credits :)
  • 1

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#27 Legendary_Agent

Legendary_Agent

    GMC Member

  • GMC Member
  • 369 posts

Posted 26 July 2015 - 08:15 AM

Thank you very much :) ill be sure to include your name in the credit section. If u would like to have ur real name in it send me a pm or if ure confortable sharing it here send it here instead. Again thx for such an awesome script!

Edited by Legendary_Agent, 26 July 2015 - 08:15 AM.

  • 0

#28 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 July 2015 - 10:22 AM

My nickname is fine


  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#29 Legendary_Agent

Legendary_Agent

    GMC Member

  • GMC Member
  • 369 posts

Posted 26 July 2015 - 01:08 PM

My nickname is fine

Greetings, will do then, thanks again, and have a nice sunday.


  • 0

#30 Primoz128

Primoz128

    GMC Member

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

Posted 16 September 2015 - 01:31 PM

Mozilla or something in it blocks it D:...


Edited by Primoz128, 16 September 2015 - 01:33 PM.

  • 0

Looking for a coding partner for my space RTS solar conquest project. More information: http://gmc.yoyogames...opic=563123&hl=


#31 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 16 September 2015 - 03:09 PM

Mozilla or something in it blocks it D:...

Your security settings is too high so it stops zip downloads
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button