How do I set the movement of the player?

0 favourites
  • 5 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hello Constructors!

    I am using Construct 2!

    The point is that on my target device there is ONLY ONE BUTTON AT TIME! (only LEFT... then UP... then LEFT.. you can hold only one button)

    For my platform (TV with remote control), it is important that I have a control system where I can make the player move, but he keeps moving, so I can jump horizontally.

    The rules are like this.

    Hold Right: x velocity increases to max

    Let go of right: x velocity decreases to 0

    Hold right: x velocity increases

    press up: jump - x velocity stays the same until I press left right/ to change it OR I hit the ground, then it starts decreasing again.

    So basically -

    X velocity goes back to 0 if you are on the ground

    X velocity goes to +MAX if you hold the RIGHT

    x velocity goes to -MAX if you hold LEFT

    I have found a Javascript code as well which has the above logic but I could not implement it in the Construct 2.

    Here is the code: https://docs.google.com/document/d/15Sdv9p3hMugA7W8QQ-Fj7luX_XYaGBAmuMQaWny0lKg/edit?usp=sharing

    Your response in this regard will highly be appreciated.

    Thanks

  • I don't see the problem. Check which key is being held and simulate this control.

    Key Right is down -> Simulate Right

    Key Left is down -> Simulate Left

    Key Up is down -> Simulate Jump

  • Thank you so much dop2000, for your response.

    Actually "AnyKey is down -> Simulate Right/Left" is already done.

    I want to implement the velocity logic with these buttons like:

    Horizontal Movement: Acceleration:

    • When moving left or right, the player’s horizontal velocity (currentVelocity) increases based on acceleration until it reaches maxVelocity (either positive for right or negative for left).
    • Direction Change: When switching directions, the player experiences double deceleration briefly to create a responsive feel when turning.
    • The direction property is updated to indicate the direction (-1 for left, 1 for right).

    Deceleration:

    • If no horizontal movement keys are pressed and the player is on the ground, the player decelerates until currentVelocity reaches zero.
    • Deceleration is applied differently based on the current direction and whether the player is moving left or right.

    Jumping:

    Initial Jump:

    • When the jump button is pressed and the player is on the ground, a jump is initiated by setting the player’s vertical velocity to jumpVelocity.
    • jumpStartTime is recorded to limit how long the player can hold the jump button for an extended jump.
    • A jump sound is played when the player initiates a jump.

    Extended Jump:

    • If the jump button is held after leaving the ground, an extra upward force (extraJumpVelocity) is applied for up to maxJumpDuration milliseconds after the jump starts.
    • This only applies when the player is not on the ground and the jump duration has not exceeded maxJumpDuration.
  • What behavior are you using? Many of the things you described are handled by 8direction/platform behaviors.

    I suggest using "simulate control" action, because setting velocity vectors directly doesn't always work as you think it should. Here is an example:

    github.com/Scirra/Construct-bugs/issues/6323

    Platform behavior has the same issue afaik.

    Acceleration/deceleration is handled by the behavior.

    Direction Change: you can detect when it happens (use a variable), and briefly increase Platform deceleration on the character. Say, set deceleration to 400, start a timer for 0.2s, on timer set deceleration value back to 200.

    Extended Jump: again, this is already implemented in the behavior - jump sustain setting.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great! thank you so much dop2000 for your help! you are always first to help.

    Yeah, the velocity making the problem, I will go through the issue that you mentioned.

    I have used both, the platformer and 8 direction behavior because there is need of both in the game for different logics.

    it is very helpful. I am going to try this logic.

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