The Daily Click ::. Forums ::. Klik Coding Help ::. Trying to incorporate a fastloop into an overlap event to make it work faster...
 

Post Reply  Post Oekaki 
 

Posted By Message

Chrisbo



Registered
  02/01/2002
Points
  794
10th October, 2009 at 00:16:29 -

So here is the scenario: I have an active object that I use as a sensor on another object. If the main object is moving down and the sensor overlaps a backdrop, I have an event that tells it to Stop, and set Y position to Y (main object) -1 to make it move back up. The problem is, say the main object is falling, and it falls fast. When the sensor overlaps, it could be 10 pixels deep by the time it stops, then as it's overlaping it's setting the Y position to Y-1 and slowly moves up.

I'm wondering if there is a way to make it instantly back up so it's not overlapping anymore via fastloop or another method? I used a fastloop and I can start a loop for X number of loops, but there's no way to really figure out how many loops to do it for, because the depth of the overlap varies depending on the speed of the object.

Does this make sense? I'm really hoping to find a way around this! Thanks

 
hay

MrMcFlurry



Registered
  03/08/2009
Points
  89

360 Owner
10th October, 2009 at 01:01:46 -

Bah, had a good example, cant find it now though, but, yeah, basically you do that. assuming you're using objects for collision detection about a character for a static movement engine. Like a single pixel object set at his feet that detects if his feet it the floor.

basically it's like:

detector overlaps background:start loop

on loop: move up 1 pixel

on loop
+ object is no longer overlapping: end loop

 
n/a

MrMcFlurry



Registered
  03/08/2009
Points
  89

360 Owner
10th October, 2009 at 01:18:03 -

Err, to expand on that, with that you can put in any arbitrary huge number of loops, 100000000 or whatever, as as soon as it DOESN'T overlap, the end loop action terminates it early anyway.

 
n/a

Chrisbo



Registered
  02/01/2002
Points
  794
10th October, 2009 at 01:28:14 -

So I just tried that exactly how you wrote here, and it didn't work...if I put start loop 1 time, it acts exactly the same as before. If I enter an arbitrary amount, say, start loop 100 times, any time it detects an overlap, it shoots the object up 100 pixels, even with the on loop + not overlapping event... is there something missing?

 
hay

MrMcFlurry



Registered
  03/08/2009
Points
  89

360 Owner
10th October, 2009 at 02:15:06 -

http://www.mediafire.com/download.php?z2uizmrt2ef

an example, doing quite literally what i said above object starts in the block, and as soon as events happen, it is shifted up and pushed out. loop ends when it no longer overlaps backdrop with the stop loop command, thus stopping it rising.

if you still have problems, upload what you got and ill take a look at it.

 
n/a

Chrisbo



Registered
  02/01/2002
Points
  794
10th October, 2009 at 05:06:42 -

Yeah, that's exactly how I have it set. I think MMF is doing one of those things where it just doesn't work right. It's happened many times to me. Usually it involved me having to delete all the related objects and recoding everything. Maybe this will just be the end of my engine I'm going to maybe rebuild it again at some point, but as of this minute I'm ready to pull my hair out from frustration...

 
hay

Chrisbo



Registered
  02/01/2002
Points
  794
10th October, 2009 at 05:07:34 -

BTW thanks a lot for the help and even uploading the example! I really do appreciate that. I'm sure I'll pick this back up in a few days to mess around with again, and I'll use that code to do it.

 
hay

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
10th October, 2009 at 14:14:46 -

Are you making sure to have "On loop" and then "Xoverlapping", and not "Xoverlapping" and then "On loop"? Cause it only works if "On loop" is read first.

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Chrisbo



Registered
  02/01/2002
Points
  794
10th October, 2009 at 18:34:48 -

Yeah, I have it in the right order. I've had stuff like this happen before in C&C and MMF 1.5. I would've hoped that it was fixed in developer... oh well. At least now I know the right way to do it and how to do it, so when I go back through and re-do stuff I'll know it from the beginning

 
hay

MrMcFlurry



Registered
  03/08/2009
Points
  89

360 Owner
11th October, 2009 at 23:11:46 -

wanna upload the problem code? Will see if i can debug it for you

 
n/a

Chrisbo



Registered
  02/01/2002
Points
  794
12th October, 2009 at 03:11:06 -

Yeah I might do that. I'll have to iron out a couple little things and put it together. I'll send a message to you when it's up

 
hay

bigredron



Registered
  07/04/2007
Points
  299
14th October, 2009 at 04:33:06 -

just so you know with fastloops instead of entering a huge number you can use -1 for an infinite loop. Just make sure you have a stop loop action otherwise your program will freeze.

 
n/a

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
14th October, 2009 at 09:36:11 -

Or better still, make a recursive loop:

On overlap
start loop "move object" 1 times

On loop "move object"
+ object overlapping backdrop
move object in opposite direction by 1 pixel
start fastloop "move object"

so the loop keeps calling itself until the additional conditions on the loop are false. Then you don't have to worry about stopping it. Though to be honest, I have really turned against using arbitrary number of loops to push objects back/on top of platforms. I would rather move the objects using fastloops 1 pixel at a time, and if an overlap occurs after a pixel move in either direction, simply undo the last movement, though this is less efficient as you are making more collision tests per code loop...

 
http://create-games.com/project.asp?id=1875 Image


MrMcFlurry



Registered
  03/08/2009
Points
  89

360 Owner
15th October, 2009 at 17:21:32 -

well, I suppose the quickest and most efficient method would be to move the object in chunks(minimum size the player could move without hitting new obstacles,say,height of the player active) until its out of the obstacle, and then binary cut the final chunk moved to find the correct position.

But, that's perhaps a bit over the top a solution.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click