Platform Movement - Finding slope angle?

This forum is currently in read-only mode.
From the Asset Store
A pack of 76 platform designs for a platformer game with a mushroom/jungle theme
  • I'm starting on working on something, and I need a way to find the angle of a slope. The character would slide down at a set speed depending on the slope.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'd sample the player's position to calculate the angle. Add two pv to buffer .X and .Y

    + System: Start of layout

    -> Sprite: Set 'lastX' to.X

    -> Sprite: Set 'lastY' to.Y

    + System: Always (every tick)

    -> Text: Set text to "Current slope angle: " & angle(Sprite ('lastX'), Sprite ('lastY'), Sprite.X, Sprite.Y)

    -> Sprite: Set 'lastX' to.X

    -> Sprite: Set 'lastY' to.Y

  • I'm assuming "LastX" is a private value?

    For the sliding, I just need just need to convert angle to X/Y movement values?

  • Yes, 'lastX' and 'lastY' are private variables.

    This method will give you the angle from the last tick to the current tick. It is not the angle to the next tick.

    However, something like making the speed of the sprite relative to the angle should work. But then you should make that angle relative to the direction of the force.

    For example, if you're doing a classic platformer, the downward force will be at 90�. Therefor a 30� (down to the right) slope should be treated the same as a 150� (down to the left) slope, speed related.

  • hey tula, could you please make a simple example .cap for this if you have some spare time?

    im using a platform behavior but i dont know how to add speed when going downhill and vice versa. it always just overrides the player's speed and input,resulting in player having no control over the slope. ive managed to get the player angle correspond the slope angle using the old fashioned dummy player sprite, but slope speed is kind of puzzling me. first i just ignored it, but now i want to make icy slopes that the player can slide down and try to struggle up with enough speed. i just dont know how to add/subtract to existing speed without completely overriding it.

    <img src="smileys/smiley5.gif" border="0" align="middle" />

  • I will see if i can put something toogether. In the meantime, to give you something to try on your own: The platform behavior has 2 actions, "set additional x speed" and "set additional y speed".

    Whatever value you use for them, they will add or substract (if they are negative) to the current speed. It is valid per tick, so use an always event for continous additional speed.

    the additional speed components can be calculated from an angle using sin and cos:

    x_speed = cos(angle) * factor

    y_speed = sin(angle) * factor

    You just need to differentiate when the character is walking and when sliding. And you need a way to get a dynamic factor (higher factor = faster slide)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)