Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> Anyone know what's wrong with this code?
United Kingdom
Thingy
Posted: Nov 1 2009, 06:07 AM
Quote Post


So long MFGG 2.0~
[*][*][*][*]

Group Icon
Group: Members
Posts: 1824
Member No.: 4642
Joined: 30-October 07

Status: (0d) [--]


CODE
if (!place_free(x,y+1))
{
vspeed+=gravity;
}

if (vspeed>8)
{
vspeed=8;
}

if (place_free(x+hspeed,y))
{
x+=hspeed;
}
else
if (!place_free(x,y+1)) and (place_free(x+hspeed,y-hspeed)) and (hspeed > 0)
{
x+=hspeed
y-=hspeed
}
else
if (!place_free(x,y+1)) and (place_free(x+hspeed,y+hspeed)) and (hspeed < 0)
{
x+=hspeed
y+=hspeed
}
else
{
if (hspeed<0) { move_contact_solid(180,ceil(abs(hspeed))); }
if (hspeed>0) { move_contact_solid(0,ceil(abs(hspeed))); }
hspeed=0;
}

if (place_free(x,y+vspeed))
{
y+=vspeed;
}
else
{
if (vspeed<0) { move_contact_solid(90,ceil(abs(vspeed))); }
if (vspeed>0) { move_contact_solid(270,ceil(abs(vspeed))); }
{
vspeed=0;
jump=0;
}
}

This goes with another code that sets the hspeed, I built slopes into this, but it won't go up them.


--------------------
user posted image
Old ref, Current ref
Click to see the rest. (opens sig on top post)

user posted image
Hey, MFGG 3.0, it's me from the past.
PMEmail PosterMSN
Top
Japan
Soiyeruda
Posted: Nov 1 2009, 07:36 AM
Quote Post


Because retarded looking women is fun. :S
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08

Status: (0d) [--]


Just from looking at it, the part where it's suppose to go up slopes seems iffy to me.

The line:
CODE

if (!place_free(x,y+1)) and (place_free(x+hspeed,y-hspeed)) and (hspeed > 0)


If I recall, would make it where if you're just touching the ground, then you'll do some weird bouncing thing (because technically, as long as there's not a low ceiling, the coordinates you specify is "free").

It's easier to do something like

CODE

if place_free(x+hspeed,y)
{//insert normal movement here}
else if place_free(x+hspeed,y-1)
{//insert slope movement here}


This way, it'll only do slope movement if it's not possible to move along a flat area.
PMEmail Poster
Top
United Kingdom
Thingy
Posted: Nov 1 2009, 08:00 AM
Quote Post


So long MFGG 2.0~
[*][*][*][*]

Group Icon
Group: Members
Posts: 1824
Member No.: 4642
Joined: 30-October 07

Status: (0d) [--]


QUOTE (Soiyeruda @ Nov 1 2009, 01:36 PM)
Just from looking at it, the part where it's suppose to go up slopes seems iffy to me.

The line:
CODE

if (!place_free(x,y+1)) and (place_free(x+hspeed,y-hspeed)) and (hspeed > 0)


If I recall, would make it where if you're just touching the ground, then you'll do some weird bouncing thing (because technically, as long as there's not a low ceiling, the coordinates you specify is "free").

It's easier to do something like

CODE

if place_free(x+hspeed,y)
{//insert normal movement here}
else if place_free(x+hspeed,y-1)
{//insert slope movement here}


This way, it'll only do slope movement if it's not possible to move along a flat area.

Thing is, the movement doesn't only go up to one, so I have to use hspeed, which is why I did two of them.

I'll try just that but with both of them for now.

EDIT:
Now using:
CODE
if (!place_free(x,y+1))
{
vspeed+=gravity;
}

if (vspeed>8)
{
vspeed=8;
}

if (place_free(x+hspeed,y))
{
x+=hspeed;
}
else
if (place_free(x+hspeed,y-hspeed)) and (hspeed > 0)
{
x+=hspeed
y-=hspeed
}
else
if  (place_free(x+hspeed,y+hspeed)) and (hspeed < 0)
{
x+=hspeed
y+=hspeed
}
else
{
if (hspeed<0) { move_contact_solid(180,ceil(abs(hspeed))); }
if (hspeed>0) { move_contact_solid(0,ceil(abs(hspeed))); }
hspeed=0;
}

if (place_free(x,y+vspeed))
{
y+=vspeed;
}
else
{
if (vspeed<0) { move_contact_solid(90,ceil(abs(vspeed))); }
if (vspeed>0) { move_contact_solid(270,ceil(abs(vspeed))); }
{
vspeed=0;
jump=0;
}
}


But it still doesn't work.

This post has been edited by Thingy on Nov 1 2009, 08:03 AM


--------------------
user posted image
Old ref, Current ref
Click to see the rest. (opens sig on top post)

user posted image
Hey, MFGG 3.0, it's me from the past.
PMEmail PosterMSN
Top
Unspecified
Miles
Posted: Nov 1 2009, 09:01 AM
Quote Post


Y HALO THAR


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

Status: (0d) [--]


Lots of things, good sir. Just a hint, try not to ever do things like x+=hspeed, as whenever you set hspeed, vspeed, gravity, and gravity_direction (which should be 270 unless you're gonna do advanced stuff, but let's leave that for now), game maker automatically moves the object... you're gonna make it go crazy. Just set the variables and game maker will work its own set of magic for you. Use that knowledge to change your code and it ought to work better.

Also, place_free isn't the best thing to use. I'd use position_meeting(x,y+1,landobjectnamegoeshere), though the only problem with that is that you have to duplicate that for multiple land objects (unless you have them set to a parent.)

This post has been edited by Miles on Nov 1 2009, 09:02 AM


--------------------
No, I'm not that Tails character. Silly you, jumping to conclusions like that!
PMEmail PosterAOL
Top
United Kingdom
Thingy
Posted: Nov 1 2009, 12:01 PM
Quote Post


So long MFGG 2.0~
[*][*][*][*]

Group Icon
Group: Members
Posts: 1824
Member No.: 4642
Joined: 30-October 07

Status: (0d) [--]


QUOTE (Miles @ Nov 1 2009, 03:01 PM)
Lots of things, good sir. Just a hint, try not to ever do things like x+=hspeed, as whenever you set hspeed, vspeed, gravity, and gravity_direction (which should be 270 unless you're gonna do advanced stuff, but let's leave that for now), game maker automatically moves the object... you're gonna make it go crazy. Just set the variables and game maker will work its own set of magic for you. Use that knowledge to change your code and it ought to work better.

Also, place_free isn't the best thing to use. I'd use position_meeting(x,y+1,landobjectnamegoeshere), though the only problem with that is that you have to duplicate that for multiple land objects (unless you have them set to a parent.)

It's variable movement, e.g. you start slow and speed up, and then slow down again when you release.

I need it to have them.

And place_free is just to check that space is empty, it works okay.


--------------------
user posted image
Old ref, Current ref
Click to see the rest. (opens sig on top post)

user posted image
Hey, MFGG 3.0, it's me from the past.
PMEmail PosterMSN
Top
Unspecified
Miles
Posted: Nov 1 2009, 02:09 PM
Quote Post


Y HALO THAR


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

Status: (0d) [--]


place_free does work, but you'll be walking on enemies and anything else whether you want to walk on it or not.

Also, for variable movement, use hspeed+=1 or hspeed-=1 to set it relative.

This post has been edited by Miles on Nov 1 2009, 02:09 PM


--------------------
No, I'm not that Tails character. Silly you, jumping to conclusions like that!
PMEmail PosterAOL
Top
Japan
Soiyeruda
Posted: Nov 1 2009, 05:21 PM
Quote Post


Because retarded looking women is fun. :S
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08

Status: (0d) [--]


QUOTE (Miles @ Nov 2 2009, 04:09 AM)
place_free does work, but you'll be walking on enemies and anything else whether you want to walk on it or not.

Also, for variable movement, use hspeed+=1 or hspeed-=1 to set it relative.

place_free checks for anything that is solid. You don't seriously make every object in your game solid, do you? Enemies, for example, don't need to be solid. >.>

Also, he seems aware of how to do variable movement if he can do x+=hspeed, which is basically the same thing.
PMEmail Poster
Top
Unspecified
Miles
Posted: Nov 1 2009, 08:03 PM
Quote Post


Y HALO THAR


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

Status: (0d) [--]


Oh, well... sorry. But the x+=hspeed is still unnecessary, as hspeed automatically moves the object. Just saying.


--------------------
No, I'm not that Tails character. Silly you, jumping to conclusions like that!
PMEmail PosterAOL
Top
United States
Elyk
Posted: Nov 1 2009, 10:51 PM
Quote Post


Standard Member
[*][*][*][*]

Group Icon
Group: Members
Posts: 6604
Member No.: 3808
Joined: 22-May 07

Status: (0d) [--]


QUOTE (Soiyeruda @ Nov 1 2009, 05:21 PM)
place_free checks for anything that is solid. You don't seriously make every object in your game solid, do you? Enemies, for example, don't need to be solid. >.>

it would still be better to use place_meeting and a parent floor object

This post has been edited by Elyk on Nov 1 2009, 10:52 PM


--------------------
user posted image
PMEmail PosterUsers WebsiteAOLMSN
Top
United Kingdom
Thingy
Posted: Nov 2 2009, 03:04 AM
Quote Post


So long MFGG 2.0~
[*][*][*][*]

Group Icon
Group: Members
Posts: 1824
Member No.: 4642
Joined: 30-October 07

Status: (0d) [--]


Either way, I doubt changing my collision script will make slopes work.

I'll do it, though.


And it didn't do anything.

Top notch advice guys.

This post has been edited by Thingy on Nov 2 2009, 04:11 AM


--------------------
user posted image
Old ref, Current ref
Click to see the rest. (opens sig on top post)

user posted image
Hey, MFGG 3.0, it's me from the past.
PMEmail PosterMSN
Top
Japan
Soiyeruda
Posted: Nov 2 2009, 05:36 AM
Quote Post


Because retarded looking women is fun. :S
[*][*][*][*][*]
[*][*][*]

Group Icon
Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08

Status: (0d) [--]


QUOTE (Elyk @ Nov 2 2009, 12:51 PM)
it would still be better to use place_meeting and a parent floor object

But that's so much work. D:

True.

QUOTE (Miles)

Oh, well... sorry. But the x+=hspeed is still unnecessary, as hspeed automatically moves the object. Just saying.

I was actually going to say this in my last post. Only thing that stopped me was that I was incredibly short on time and needed to catch a school bus.
PMEmail Poster
Top
United Kingdom
Thingy
Posted: Nov 4 2009, 11:36 AM
Quote Post


So long MFGG 2.0~
[*][*][*][*]

Group Icon
Group: Members
Posts: 1824
Member No.: 4642
Joined: 30-October 07

Status: (0d) [--]


Now that we're done pointing out non-slope-related things, why not give me some actual help?


--------------------
user posted image
Old ref, Current ref
Click to see the rest. (opens sig on top post)

user posted image
Hey, MFGG 3.0, it's me from the past.
PMEmail PosterMSN
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.0720 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.63 ]