I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: 128-Up on July 21, 2015, 01:44:19 PM

Title: "Pushing" the player?
Post by: 128-Up on July 21, 2015, 01:44:19 PM
I'm using Lemon Engine and trying to create something so that an object pushes the Kid while he's touching it. (Basically a conveyor, but also applied to the air.) I think late rooms in Challenge 100 Trials used this kind of mechanic.

I noticed that it works perfectly... so long as the Kid's not touching the ground. Trying to remedy this with making a conveyor block still doesn't affect the Kid. What's causing the blocks to make the player unaffected by the pushing object?
Title: Re: "Pushing" the player?
Post by: Derf on July 21, 2015, 02:10:14 PM
I also use Lemon Engine, I'm very fond of it.

I just created a conveyor belt block in my game to test this and it works fine. Here's the code:

Code: [Select]
if(collision_rectangle(x,y,x+32,y-128,player,1,0)) {
     player.hspeed += 0.75;
}

If you put that in a block object's step event it will function as a conveyor belt when you're on it and also when you're within 128 pixels above it.

If I misinterpreted what you wanted and you just wanted two separate objects, one that is an block that accelerated you when touching it and another that you pass through in the air but that also accelerates you. Then you put "player.hspeed += 0.75;" or whatever acceleration you want in a collision event of both a solid block parented object and a pass-through object.
Title: Re: "Pushing" the player?
Post by: 128-Up on July 21, 2015, 03:06:37 PM
That works but it seems like the effect is doubled if the player's touching two of the objects at once, and I'm not sure how to make it so that even if it's touching multiple pushing objects the strength is the same as if only one was touched.
Title: Re: "Pushing" the player?
Post by: Derf on July 21, 2015, 03:23:51 PM
Hmm.

Could always take the collisions out of the objects and put them in a controller object that checks if the player is colliding with any of them and applies the code itself which will therefore only be once?
Title: Re: "Pushing" the player?
Post by: YoSniper on July 21, 2015, 04:34:51 PM
Try this:

In the player's Step Event, include this piece of code, or similar:
Code: [Select]
if collision_line(x, y, x, y + 32, objConveyorBlock, true, true) {
    hspeed += 0.75;
}

You would have to distinguish between left and right conveyors eventually, but this should be a start. Also note that the player's hspeed gets reset at the beginning of each step, so you need not worry about the player accelerating to the right.