| |
Anyone know what's wrong with this code?
Thingy |
|

So long MFGG 2.0~
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Minigame Comp Runner Up Badge (2) [*]](https://archive.mfgg.net/html/badges/mcr2.gif) ![Minigame Comp Third Place Badge (2) [*]](https://archive.mfgg.net/html/badges/mct2.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

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

|
| 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.
--------------------
|
|
|
Soiyeruda |
|

Because retarded looking women is fun. :S
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Super Reviewer Badge [*]](https://archive.mfgg.net/html/badges/reviews.gif) ![Sprite Comp Top 5 Badge (1) [*]](https://archive.mfgg.net/html/badges/sct1.gif) ![Drawing Comp Top 5 Badge (3) [*]](https://archive.mfgg.net/html/badges/dct3.gif) ![Minigame Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/mcr1.gif)
![Minigame Comp Third Place Badge (2) [*]](https://archive.mfgg.net/html/badges/mct2.gif) ![Music Comp Third Place Badge (1) [*]](https://archive.mfgg.net/html/badges/uct1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 3589
Member No.: 5004
Joined: 6-March 08
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
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.
|
|
|
Thingy |
|

So long MFGG 2.0~
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Minigame Comp Runner Up Badge (2) [*]](https://archive.mfgg.net/html/badges/mcr2.gif) ![Minigame Comp Third Place Badge (2) [*]](https://archive.mfgg.net/html/badges/mct2.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

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

|
| 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
--------------------
|
|
|
Miles |
|
Y HALO THAR

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

|
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!
|
|
|
Thingy |
|

So long MFGG 2.0~
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Minigame Comp Runner Up Badge (2) [*]](https://archive.mfgg.net/html/badges/mcr2.gif) ![Minigame Comp Third Place Badge (2) [*]](https://archive.mfgg.net/html/badges/mct2.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

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

|
| 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.
--------------------
|
|
|
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.0725 ] [ 13 queries used ] [ GZIP Enabled ] [ Server Load: 1.82 ]
| |