[Solved]Gradually steering the car using the car behavior

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi

    I'm creating a top down racing game, and everything is working great. The only problem I have is that the car steers very abruptly. I know the steering can be edited by changing the steer speed value. Setting the steering speed to a lower value causes the car to have a huge turning radius tho, which is not what I want since this makes maneuvering between objects to hard for the player.

    Is there a way to have the car steer faster the longer the player holds the key down?

    Thanks in advance

  • You could try setting a global variable and setting the steering speed to that variable every tick. Then, on key down, start increasing the variable, and on key up reset it to the original amount. Or you could just directly increase the steering speed. I have never played with cars, so I don't know if that's possible.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi Mathijs90,

    One way you might approach this is with a custom variable to represent the turning rate.

    I'll call this variable "turnRate".

    You can think of this variable as keeping track of the steering wheel position, with "0" meaning centered, positive numbers steering right-wards, and negative numbers steering left-wards.

    The events that allow the player to control this variable should do the following:

    When you hold RightArrow the turnRate value will gradually increase up to a cap value (e.g. +300),

    and when you hold LeftArrow the turnRate value will gradually decrease down to a cap value (e.g. -300).

    When you're not holding any keys, the turnRate value will gradually move towards 0.

    To get the Car behavior to use this variable for steering, you'll first need to disable "Default Controls".

    In the layout, select the car, and in the car's properties, in the section Behaviors > Car, find "Default Controls", and set it to "No".

    This disables the automatic key bindings that control the car.

    Don't worry, you can manually recreate these key bindings with events, using the car's "Simulate Control" action.

    Recreate the key bindings for acceleration and breaking as follows:

    UpArrow is held down: For Car: Simulate Control - Accelerate.

    DownArrow is held down: For Car: Simulate Control - Break.

    To link the turnRate variable to the car's steering create the following events:

    Every tick: For Car: Set steer speed to turnRate.

    Every tick: For Car: Simulate Control - Steer right.

    It looks weird, but what's going on is that the car now always thinks it's steering to the right, but by the amount stored in the turnRate variable.

    When turnRate is positive, the car will turn right.

    When turnRate is negative the car will turn left. (a "negative" right turn)

    And when turnRate is 0 the car will go straight.

    As a final thought, you may want to make the turnRate return to 0 much faster than it gradually climbs away from 0, i.e. when turning left or right. Even though realistically, a human driver really would have to turn the steering wheel back to center manually, for a game, the controls will probably feel more responsive if the return to center occurs in a fraction of a second.

    This rapid return to center should obviously take effect when a player is not holding a turning key, but it should also occur when a player is holding a turning key that is currently turning the wheels back to center. In that latter case, once the wheels get back to center, (and the key is now turning the wheels away from center), the steering can go back to being more gradual.

    Hope that helps.

  • Hi McDonald & fisholith,

    Apologies for the late response, I wasn't near a computer for the last couple days.

    I think you both meant the same thing and were both right, because it's working now. I'm not very good at math or programming however (being a designer rather than the former), so the very detailed description from fisholith was extremely helpful. Couldn't have done it without all the explanation, thanks to the both of you!

    Cheers & have a great weekend!

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