The Daily Click ::. Forums ::. Klik Coding Help ::. Stuck with CPE
 

Post Reply  Post Oekaki 
 

Posted By Message

SephirothClone13



Registered
  04/06/2009
Points
  28
9th June, 2009 at 23:46:00 -

I had a little trouble trying to stop the movement of an object when a collision is detected. I had an event which looked like this:

+ X Position of Active2 >= X Postition of Active + Object Width (Active)
+ Repeat while "Right" is pressed
- Set X Position to X Active +5

I set an alterable value to keep the object's width recorded. So it would move to the right, but it wont move beyond the obstacle, even when it jumps.

help please

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
10th June, 2009 at 00:09:34 -

It won't go past the obstacle because you programmed it not to. O_o

 

  		
  		

SephirothClone13



Registered
  04/06/2009
Points
  28
10th June, 2009 at 01:05:44 -

Oh, how stupid of me... I forgot to actually post my question...

HOW do i make it so I can jump over the other active object but not be able to walk through it?

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
10th June, 2009 at 02:17:08 -

Well you could compare the Y values in a similar fashion, but I foresee trouble with this setup, especially if you have many obstacles near each other. Can you not just use conventional collision detection? It's really not all that awful, is it?

 

  		
  		

SephirothClone13



Registered
  04/06/2009
Points
  28
10th June, 2009 at 02:34:27 -

Well I've tried setting collisions up that way, but the only logical thing I can think to set the X value to is the X position of the object and that doesn't work. It's not like I can right-click and choose Movement > Stop, so how would i set that up? Of all the little silly things... Things has probably been the most stressful lol

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
10th June, 2009 at 02:40:17 -

What system are you using? If you go with fastloops, you should be able to move the character unless he's overlapping the obstacle. Even without fastloops you could.

Or did I misunderstand something?

 

  		
  		

SephirothClone13



Registered
  04/06/2009
Points
  28
10th June, 2009 at 02:45:12 -

By system you mean...? I haven't had had much expeience with loops, but I'll go away and give it a try If I get stuck i'll just come back and enquire about other ways lol.

and no, i think you got where i was goin with it. Thanks for the suggestion

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
10th June, 2009 at 02:56:00 -

Not sure I was very much help, but glad if I was. There are other more experienced fastloop coders here than me, so just ask whatever questions you may have.

 

  		
  		

SephirothClone13



Registered
  04/06/2009
Points
  28
10th June, 2009 at 13:37:50 -

I didn't know whether or not to post as a new thread, but it's still the same problem so I'll leave it here for now...

So my loop event sets the X position of my object too far away... But at least I can see that the method works... Could somebody help me fix this so that the player object (Active) stops when it touches the other object (Object)?

Here's what I have thus far:

+ Active is facing right
+ Collision between Active and Object
- Start loop "Collide" ObjectWidth(Active) number of times

+ On loop Collide
- Set X position of Active = X position of Active -1

+ Always
+ X position of Active = X position of Object - ObjectWidth(Active)
- Stop loop "Collide"

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
10th June, 2009 at 16:12:26 -

First thing, even if all that would be right, the "Always" in the last event is useless since you have another condition.
It should start with "On loop Collide" though. That is because, when you start a loop, you stop the normal flow of events, and all none-loop events are ignored until this loop is finished. So for the loop to stops, the event that makes it stop needs to be in the loop.

Onto the main problem now:
Unless I don't understand what you want to accomplish or you only need one obstacle or this is for a cutscene or something, this isn't the way to do collision detection.

You're doing things in the wrong order. My guess is that your moving active moves by a couple of pixels every frame isn't it? So, when it touches the wall(or wathever) it overllaps it by a variable ammount of pixels. So, you shouldn't use the fastloop to get him out of the wall, but rather to move him all the time. In your loop, move the player by 1 pixel. still in the same loop, if he hits the wall, send him in the other direction by 1. So this checks for collision every pixel, this way, the player won't be stuck or bounce on the walls because he was sent back to far. And the number of loops determines the speed of all this.

You should still check for platform movement tutorials before you go any further IMO.
Here's a good one: http://www.clickteam.com/eng/resources/fastloop_plattutorial.zip
I hope that I didn't misunderstand. Your question

 
...

SephirothClone13



Registered
  04/06/2009
Points
  28
10th June, 2009 at 16:45:45 -

If you set a loop to only loop once, does that make the loop kinda redundant? Only wondering because I took your advise and changed my collision events to this:

+ Active is facing right
+ Collision between Active and Object
- Start loop "Collide" 1 number of times

+ On loop Collide
- Set X position of Active = X position of Active -1

+ On Loop Collide
+ X position of Active < X position of Object - ObjectWidth(Active)
- Stop loop "Collide"
- Set X position of Active = X position of Active +1

This works now, but looking at it I was thinking that since it only loops once I could take out the loop and set a flag in it's place. So when the objects collide, set falg to 1, and then where i stopped the loop i could set the flag to 0 again. Would this work equally well?

I know it's the same amount of events, but I'm thinkning of in the future when I may need to design complex loops. Thanks for the help guys

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
10th June, 2009 at 17:40:13 -

Well the idea of a loop is to repeat events many times in a frame. It can logically come to 1 or even 0 in the number of loop is a variable, but as you made it, a fix once per frame seems useless. Perhaps it could be a way to have a list of events that each stop the loop, so that that the fisrt wich returns true is the only one to happen, but that could also be done with a flag. So I see no use for a 1 loop "fast" loop.

Now... there are so many wrong things about your lines. First, think that at some point you'll have many obstacle, so you wan't to move the player independantly from the objects positions and width (or anything else). For efficiency, these obstacles should be backdrops anyway (With "obstable type" set as "obstacle" in the backdrop object's runtime properties) and you can't access their position and width in the event editor. The good way to do it, as I said, is to move the guy by one pxl, and quick him out by 1 pxl when he collides with any backdrop. This way, it'll be a universal rule wich'll work for every obstacle.

Also, forget the "Active is facing right". You don't want to have a different loop for every direction. Make an event that changes a value to a positive number when you press right. Make the same value go negative when you press left, and change it to zero when both direction aren't held. Then:

If Value <> 0
Set X pos of Active to: X position of Active + Value.

Now «GO» study that tutorial I linked in my previous post, and if you don't get something, just PM me


 
...

SephirothClone13



Registered
  04/06/2009
Points
  28
10th June, 2009 at 18:34:19 -

Thanks for the wealth of information I figured as much, but thought I'd check because, like I said, I haven't had much experience with looping.

Now, for me to clear some things up I appreciate the constructive criticism about the way I've organised my events, however, It is not a platformer that I am working on; there is only one obstacle in this frame and that is another player object.

Had I been working on a platformer I definitely would've just used backdrops set as obstacles. I picked that up when I made my first game (a space invaders clone). I shall definitiely take in all of the techniques you have provided me with for when I take on future prjects

Thanks again

 
n/a
   

Post Reply



 



Advertisement

Worth A Click