Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> This collision code, GM7
United States
SuperMarioMaster
Posted: Oct 31 2009, 08:25 PM
Quote Post


It's been real
[*]

Group Icon
Group: Members
Posts: 2145
Member No.: 4476
Joined: 22-September 07

Status: (0d) [--]


It ain't working as well as I had hoped
Code:

Step:
CODE
//blah gravity
gravity_direction = 270
gravity = 0.5
//blah falling
if vspeed < 12
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 !place_free(x,y+1) {
vspeed = 0
move_contact_solid(direction,12)
gravity = 0 }

Sounds like it should work, but he keeps stopping way above ground(even though he has a mask). and shortly warps past the ground.

I haven't any idea what I did wrong here


--------------------
PMEmail Poster
Top
United States
Datt
Posted: Oct 31 2009, 08:32 PM
Quote Post


I'm having a blast
[*][*]

Group Icon
Group: Members
Posts: 1022
Member No.: 4623
Joined: 24-October 07

Status: (0d) [--]


did you make sure obj_land is solid?

This post has been edited by Datt on Oct 31 2009, 08:33 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?

PMUsers Website
Top
United Kingdom
Ludwig22
Posted: Oct 31 2009, 08:34 PM
Quote Post


Koopa Komposer Extraodinaire


Group Icon
Group: Members
Posts: 227
Member No.: 6485
Joined: 30-August 09

Status: (0d) [--]


QUOTE (Datt @ Oct 31 2009, 08:32 PM)
did you make sure obj_land is solid?

How could he forget something like that?


--------------------
PMEmail PosterUsers Website
Top
United States
Datt
Posted: Oct 31 2009, 08:36 PM
Quote Post


I'm having a blast
[*][*]

Group Icon
Group: Members
Posts: 1022
Member No.: 4623
Joined: 24-October 07

Status: (0d) [--]


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?

PMUsers Website
Top
Unspecified
Miles
Posted: Oct 31 2009, 08:52 PM
Quote Post


Y HALO THAR


Group Icon
Group: Members
Posts: 71
Member No.: 1468
Joined: 22-September 05

Status: (0d) [--]


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!
PMEmail PosterAOL
Top
United States
OniLink10
Posted: Oct 31 2009, 08:58 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


Your problem is that you are checking if the vspeed is LESS THAN 12, and if it is, it is set to 12. You want to make sure that vspeed does not go OVER 12, not UNDER 12. Change that less than to a greater than.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Datt
Posted: Oct 31 2009, 09:00 PM
Quote Post


I'm having a blast
[*][*]

Group Icon
Group: Members
Posts: 1022
Member No.: 4623
Joined: 24-October 07

Status: (0d) [--]


QUOTE (Miles @ Oct 31 2009, 08:52 PM)
Place_free? NO. NO NO NO. BAD YOU. Also, above, that will not fix it.

It should now. Atleast it worked for me when I just tried it.


--------------------
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?

PMUsers Website
Top
United States
SuperMarioMaster
Posted: Oct 31 2009, 09:07 PM
Quote Post


It's been real
[*]

Group Icon
Group: Members
Posts: 2145
Member No.: 4476
Joined: 22-September 07

Status: (0d) [--]


QUOTE
CODE
if y < other.y-16
{vspeed=0;y=other.y-32 **change the 32 to sprite height**}

I made it the exact height of the mask, but he just keeps jumping up and down

This post has been edited by SuperMarioMaster on Oct 31 2009, 10:38 PM


--------------------
PMEmail Poster
Top
Sweden
Alex
Posted: Nov 1 2009, 06:29 AM
Quote Post


In Donaldismo Veritas
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 1678
Member No.: 5509
Joined: 9-July 08

Status: (0d) [--]


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.


--------------------
user posted image
--------------------
My character has been drawn by:
NICKtendo DS
Jazz
Tek
PM
Top
Unspecified
Miles
Posted: Nov 1 2009, 09:25 AM
Quote Post


Y HALO THAR


Group Icon
Group: Members
Posts: 71
Member No.: 1468
Joined: 22-September 05

Status: (0d) [--]


Oops! Take out the then in that part of the code. Sorry.


--------------------
No, I'm not that Tails character. Silly you, jumping to conclusions like that!
PMEmail PosterAOL
Top
Sweden
Alex
Posted: Nov 1 2009, 09:36 AM
Quote Post


In Donaldismo Veritas
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 1678
Member No.: 5509
Joined: 9-July 08

Status: (0d) [--]


btw how does with and then work? I don't really understand them :/


--------------------
user posted image
--------------------
My character has been drawn by:
NICKtendo DS
Jazz
Tek
PM
Top
Unspecified
Miles
Posted: Nov 1 2009, 10:03 AM
Quote Post


Y HALO THAR


Group Icon
Group: Members
Posts: 71
Member No.: 1468
Joined: 22-September 05

Status: (0d) [--]


with objectname_or_instanceid
{
docrapforthatspecificobject
}

I think that's how that works, anyway.

'then' comes after any if you want it to. if a then b.


--------------------
No, I'm not that Tails character. Silly you, jumping to conclusions like that!
PMEmail PosterAOL
Top
Canada
Mariofany
Posted: Nov 1 2009, 10:59 AM
Quote Post


Regular
[*]

Group Icon
Group: Members
Posts: 552
Member No.: 4858
Joined: 22-December 07

Status: (0d) [--]


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
PMEmail PosterAOLYahooMSN
Top
United States
Datt
Posted: Nov 1 2009, 12:50 PM
Quote Post


I'm having a blast
[*][*]

Group Icon
Group: Members
Posts: 1022
Member No.: 4623
Joined: 24-October 07

Status: (0d) [--]


QUOTE (SuperMarioMaster @ Oct 31 2009, 09:07 PM)
I made it the exact height of the mask, but he just keeps jumping up and down

hmm really?

Lets see... What is the height of obj_land? Try changing the 16 to the height of obj_land. If that doesn't work, try setting the 32 to one more or less than the height of the character mask.


--------------------
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?

PMUsers Website
Top
United States
SuperMarioMaster
Posted: Nov 1 2009, 12:57 PM
Quote Post


It's been real
[*]

Group Icon
Group: Members
Posts: 2145
Member No.: 4476
Joined: 22-September 07

Status: (0d) [--]


Well setting it to 17 (where the center is) made him stop jumping
but he now he can't move


--------------------
PMEmail Poster
Top
United States
Datt
Posted: Nov 1 2009, 02:10 PM
Quote Post


I'm having a blast
[*][*]

Group Icon
Group: Members
Posts: 1022
Member No.: 4623
Joined: 24-October 07

Status: (0d) [--]


QUOTE (SuperMarioMaster @ Nov 1 2009, 11:57 AM)
Well setting it to 17 (where the center is) made him stop jumping
but he now he can't move

Is sprite origin of obj_land in the center too?
I don't know this usually works for me, try one of the other posts if you can't figure it out D:

This post has been edited by Datt on Nov 1 2009, 02:15 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?

PMUsers Website
Top
United States
SuperMarioMaster
Posted: Nov 1 2009, 02:39 PM
Quote Post


It's been real
[*]

Group Icon
Group: Members
Posts: 2145
Member No.: 4476
Joined: 22-September 07

Status: (0d) [--]


QUOTE (Datt @ Nov 1 2009, 03:10 PM)
Is sprite origin of obj_land in the center too?
I don't know this usually works for me, try one of the other posts if you can't figure it out D:

Nope

and it's for the minigame comp so I don't think I'm aloud to have that big of changes from people


--------------------
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0802 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.75 ]