| |
This collision code, GM7
Datt |
|
I'm having a blast
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 1022
Member No.: 4623
Joined: 24-October 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (Ludwig22 @ Oct 31 2009, 08:34 PM) | | How could he forget something like that? |
Its actually pretty easy to forget something that simple. Plus that sounds like the problem anyways.
edit: fixed. Use these. They should work.
Step:
| CODE | //blah gravity gravity_direction = 270 gravity = 0.5 //blah falling if vspeed > 12 **you had a < sign here, where it should have been a >** vspeed = 12 //blah movement if keyboard_check(vk_left) && !place_meeting(x+1,y,obj_land) { image_xscale = 1 } if keyboard_check(vk_right) && !place_meeting(x-1,y,obj_land) { image_xscale = -1 } |
Collision with obj_land:
| CODE | if y < other.y-16 {vspeed=0;y=other.y-32 **change the 32 to sprite height**}
|
move_contact_solid is buggy and shouldn't really be used. Thats why I didn't use it. Or you can do what the bottom post does, both of the posts should work.
This post has been edited by Datt on Oct 31 2009, 09:08 PM
--------------------
| QUOTE (Mario_6464SMR's reply to Mrs A) | | his name's not Halo it's the master chief, and i don't know what "doesn't afraid of anything" means, have u ever played halo before? |
|
|
|
Miles |
|
Y HALO THAR

Group: Members
Posts: 71
Member No.: 1468
Joined: 22-September 05
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
Place_free? NO. NO NO NO. BAD YOU. Also, above, that will not fix it.
This is my personal favorite method, taken from my engine. It accidentally adds support for going up certain slopes, actually.
Put this in a begin step event, for collision. Copy the each position_meeting line and replace the object with any other object you want to land on. You may need to erase some parts of your code that touch gravity and stuff since it interferes with this code, below:
| CODE | Floor=0; gravity_direction=270; gravity=0.5;
if position_meeting(x,y+1,obj_land) && vspeed>=0 then Floor=1;
if Floor then { vspeed=0; gravity=0; while position_meeting(x,y,obj_land) then y-=1; } else { if vspeed>12 then vspeed=12; }
|
The object does not have to be solid. It's best if it isn't, actually, but that depends on how you make walls etc.
I can make a wall code like this if you want.
This post has been edited by Miles on Oct 31 2009, 08:59 PM
--------------------
No, I'm not that Tails character. Silly you, jumping to conclusions like that!
|
|
|
Alex |
|

In Donaldismo Veritas
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Drawing Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/dcg2.gif) ![Drawing Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/dcr1.gif) ![Drawing Comp Top 5 Badge (5+) [*]](https://archive.mfgg.net/html/badges/dct5.gif) ![Minigame Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/mcg1.gif)
![Minigame Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/mcr1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 1678
Member No.: 5509
Joined: 9-July 08
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (Miles @ Nov 1 2009, 02:52 AM) | Place_free? NO. NO NO NO. BAD YOU. Also, above, that will not fix it.
This is my personal favorite method, taken from my engine. It accidentally adds support for going up certain slopes, actually.
Put this in a begin step event, for collision. Copy the each position_meeting line and replace the object with any other object you want to land on. You may need to erase some parts of your code that touch gravity and stuff since it interferes with this code, below:
| CODE | Floor=0; gravity_direction=270; gravity=0.5;
if position_meeting(x,y+1,obj_land) && vspeed>=0 then Floor=1;
if Floor then { vspeed=0; gravity=0; while position_meeting(x,y,obj_land) then y-=1; } else { if vspeed>12 then vspeed=12; }
|
The object does not have to be solid. It's best if it isn't, actually, but that depends on how you make walls etc.
I can make a wall code like this if you want.
|
I got this:
| QUOTE | ___________________________________________ FATAL ERROR in action number 1 of Begin Step Event for object object0:
COMPILATION ERROR in code action Error in code at line 11: while position_meeting(x,y,obj_land) then y-=1;
at position 39: Unexpected symbol in expression.
|
--------------------
|
|
|
Mariofany |
|
Regular
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif)

Group: Members
Posts: 552
Member No.: 4858
Joined: 22-December 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (SuperMarioMaster @ Oct 31 2009, 06:07 PM) | | I made it the exact height of the mask, but he just keeps jumping up and down |
Well, here's what I did
Make some collision variables
| CODE | ground = place_meeting(x, y+1, Block); ceiling = place_meeting(x, y-1, Block); lWall = place_meeting(x-1, y, Block); rWall = place_meeting(x-1, y, Block); stuck = place_meeting(x, y, Block);
|
Handle Collisions
| CODE | if (!ground) { if (gravity < 1) gravity = 1; } else { gravity = 0; if (vspeed > 0) vspeed = 0; }
|
Move to contact
| CODE | // Note: I don't use the default hspeed; I set my own variables // keyHspeed = the hspeed from key presses // Other Hspeed is the hspeed from other stuff, like when the player's on Conveyor belts? if (keyHspeed > 0) { for (kHspeed = keyHspeed; kHspeed > 0; kHspeed -= 1) { if (!place_meeting(x+keyHspeed, y, Block)) x += kHspeed + otHspeed; } } else if (keyHspeed < 0) { for (kHspeed = keyHspeed;kHspeed < 0; kHspeed += 1) { if (!place_meeting(x+kHspeed, y, Block)) x += kHspeed + otHspeed; } }
// This loop is placed here so that the player doesn't go under the ground while (vspeed > 0 && place_meeting(x, y+vspeed, Block)) { vspeed -= 1; }
// Check if the player is stuck in the ground/wall/ceiling if (stuck) move_contact_obj(Block, 13);
|
The above is all in the step event
move_contact_obj() is a script, and there's probably a way more efficient way to do this:
| CODE | for (i=0;i<argument1;i+=1) { if (!place_meeting(x-i, y, argument0)) { x-=i; exit; } if (!place_meeting(x+i, y, argument0)) { x+=i; exit; } if (!place_meeting(x, y-i, argument0)) { y-=i; exit; } if (!place_meeting(x, y+i, argument0)) { y+=i; exit; } }
for (i=0;i<argument1;i+=1) { if (!place_meeting(x-i, y-i, argument0)) { x-=i; y-=i; exit; } if (!place_meeting(x+i, y-i, argument0)) { x+=i; y-=i; exit; } if (!place_meeting(x+i, y+i, argument0)) { x+=i; y+=i; exit; } if (!place_meeting(x-i, y+i, argument0)) { x-=i; y+=i; exit; } }
|
In this code, nothing has to be solid, the player doesn't use the default hspeed, and the object, Block, can be used as the ground, wall, and ceiling
This post has been edited by Mariofany on Nov 1 2009, 11:02 AM
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
[ Script Execution time: 0.0808 ] [ 13 queries used ] [ GZIP Enabled ] [ Server Load: 2.53 ]
| |