1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

GM:S 1.4 [Solved] Moving platforms wall collision

Discussion in 'Programming' started by MaxLos, Feb 12, 2020.

  1. MaxLos

    MaxLos Member

    Joined:
    Sep 25, 2017
    Posts:
    63
    Hihi,

    So I finally got around to learning how to make moving platforms using one of Shaun's old tutorials. It works great but it has one "problem" that bothers me: if the player is standing on a moving platform that moves into a wall it kinda pushes the player a bit in that direction. Not a big deal, but again, it bothers me lol

    Moving Platform.gif

    Code:
    var hsp_final = hsp + hsp_carry;
    hsp_carry = 0;
    
    //Moving Horizontal Platforms
    if place_meeting(x,y+1,obj_horizontal_platform)
    {
        var platform = instance_place(x,y+1,obj_horizontal_platform)
        if (bbox_bottom + 1 = platform.bbox_top)
        {
            hsp_carry = platform.hsp;
        }
    }
    
    //Standard collision code here..
    
    Any idea how I would fix it? Thanks!
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    1,041
    You could try only applying the platforms hsp to hsp_carry if that platform has no collision in the direction it is moving, but ultimately End Step, or even Begin Step need to be utilised with moving platforms.
     
    Last edited: Feb 12, 2020
    MaxLos likes this.
  3. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    An easy fix would be to make platforms move in Begin Step rather than Step, so they're guaranteed to be processed before the player (and not change direction mid-process). Basically moving platforms are standing still for all other objects' perspective during the step event. Thinking of it that way makes them a lot easier to deal with.

    I'd go one step further, though: have platforms be responsible for moving anything they can push, too. Do a with loop for a platformPushable parent (or whatever) and if there's any in the platform's way (x+hsp,y+vsp) or on top of the platform (x,y-1), have them attempt to move in the same direction as the platform. (If there's an obstacle there, don't move, and/or kill the object if it's crushed between things that can crush it - this logic gets a lot messier to figure out)
     
    MaxLos and Joe Ellis like this.
  4. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    467
    I agree with @Yal on the approach, but just wanted to point out that although an undesired effect, its actually quite cool.
     
    MaxLos likes this.
  5. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    It's not gonna be as cool when he makes vertical platforms and the player gets stuck in them when they turn around :p
     
    MaxLos likes this.
  6. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    1,107
    I agree with Yal's approach, rather than dealing with it in the player's code, do it in the platform. (in begin step) before moving the platform, first check if the player is just above it, if it is move the player also by it's hsp & vsp. Then in the player's step event, after it's been moved by the platform, it's normal movement & collision will still work as you'd want it to. ei. it can still run\accelerate etc. and it ends up moving relatively with the platform in a realistic way, or a way that looks right, and the carrying naturally gets broken when the player jumps or walks off the edge of it
     
    MaxLos likes this.
  7. MaxLos

    MaxLos Member

    Joined:
    Sep 25, 2017
    Posts:
    63
    Woo! Thanks everyone! Changed it from the Step Event to the Begin Step Event and that fixed it :D
    Thanks for the advice about handling it in the platforms, I just thought it would be better performance wise to handle all the checks in one instance if possible
     
    Joe Ellis likes this.

Share This Page