Bind max speed to a variable?

0 favourites
  • 5 posts
From the Asset Store
Support AdType ( AppOpenAd, Banner Ad, Interstitial Ad Rewarded Ad, MREC Ad) support c3 build service
  • So... I'm completely new to this software. Came here from Gamemaker to see what was going on over here <img src="smileys/smiley2.gif" border="0" align="middle" />

    Anyway...

    I got a sprite with the 8Direction behavior. What I want to do is bind the Max Speed with an Instance Variable (Since I can not find a subtract/add event linked with Max Speed).

    Say it starts at 200. When I click ctrl it subtracts 100. Shift adds 100.

    So I don't have to hold down a key to change the speed. I tab it.

    Now I can imagine Gamemaker isn't too popular over here?

    But just to show what I mean in GML:

    I got a variable called playerSpeed and code looking like this:

    if keyboard_check_pressed(vk_shift)

    {

    playerSpeed += 100

    }

    if keyboard_check_pressed(vk_control)

    {

    playerSpeed -= 100

    }

    if (playerSpeed > 300)

    {

        playerSpeed = 300

    }

    if (playerSpeed < 100)

    {

        playerSpeed = 100

    }

  • It's the same kind of logic here, events replace if/else statements but functionally they're the same.

    So:

    [System] Every Tick

    [Event]     On key pressed (LShift)

    [Action]       playerSpeed = playerSpeed + 100

    If you want it incremental you just:

    [System] Every Tick

    [Event]     On key held (LShift)

    [Action]       playerSpeed = playerSpeed + 100

    And so on...

    If you haven't already, you might wanna go through a tutorial or two to get a feel for the C2 "syntax". It's real easy, but the clickiness and some of the C2 terms can feel a bit alien at first.

  • ErekT is right you can easily do this kind of logic with events.

    However, In this case you should be able to create these actions without the every tick event by adding a condition or sub-event that compares the players maxspeed to another value (in you example 100 & 300).

    And just to clarify on accessing an objects properties,

    I not sure how the gamemaker language compares but in C2 to change an objects properties you sometimes have to dig into it a bit. For example speed is part of a behavior, in this case 8direction movement, so you have to access the behavior too. To get/alter the object's speed property you would need...

    objectname.8Direction.MaxSpeed

    then you can add / subtract from it using the set maxspeed action

    action: set object's maxspeed to objectname.8Direction.MaxSpeed + 100

  • It can be really simple for the keypress checking.

    Add an instance variable for the max speed and do something like:

    when Throttle key is pressed condition on the same block with a maxSpeed>100 . Then the action set to add 1 to the max speed variable.

    That is so that 100 is the cap, and they can not hold the throttle key longer. then set a decelerate key to subtract from the maxspeed variable or have it reset on a throttle key up condition.

    It would probably take less processing power to just cap the throttle rather than trying to get the current speed of something, and then capping it.

    I can see when getting the current speed would be needed, especially if the car collides with things that will slow it down.

    The above example would be better with something like a space ship, but with a little complexity you can probably make it work for you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Keypress itself is an event so you don't have to do the every tick check. That just adds extra overhead. You should use every tick as little as possible.

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