Author Topic: "Pushing" the player?  (Read 1914 times)

128-Up

  • Spike Dodger
  • Posts: 114
  • Lives are an antiquated concept.
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Chrome 43.0.2357.134 Chrome 43.0.2357.134
    • View Profile
  • Playstyle: Keyboard
"Pushing" the player?
« 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?

Derf

  • Guest
Re: "Pushing" the player?
« Reply #1 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.

128-Up

  • Spike Dodger
  • Posts: 114
  • Lives are an antiquated concept.
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Chrome 43.0.2357.134 Chrome 43.0.2357.134
    • View Profile
  • Playstyle: Keyboard
Re: "Pushing" the player?
« Reply #2 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.

Derf

  • Guest
Re: "Pushing" the player?
« Reply #3 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?

YoSniper

  • Awexome
  • Global Moderator
  • Spike Dodger
  • Posts: 142
  • People regard me as a programming overlord.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.134 Chrome 43.0.2357.134
    • View Profile
    • My YouTube
  • Playstyle: Keyboard
Re: "Pushing" the player?
« Reply #4 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.
I don't traverse the forums as much anymore. Follow me on Twitter if you want to keep tabs on me!

Twitter: @YoSniperGames
Twitch: yosniper

Streams happen whenever I feel like it.