How do I limit rotation?

0 favourites
  • 6 posts
  • I have started a car racing game where the car follows the player touch but I want to limit the turning speed, for example if the touch does a sharp turn, the car will swerve slightly outwards to the actual path.

    I'm using a bullet to get the car to follow touch

    is there a way using the angle to do this or something?

    thank you.

  • yo!!

    ok, so if you have a

    (physics on the car btw)

    Is In touch event-------------------apply force to position( depends on the size of your car) touch.x touch.y

    every...(i did 0.00009)seconds-------and i did rotate 5 degrees towards angle

    needs ALOT of tweaking... but this gives the illusion force is being applied to the car and it accelerates to the desired position with it's speed being affected by motion

    slap in some immovable physic barriers for the track and boom!, you could even have some AI cars that have check points to drive to. loads of examples of these so enjoy

    try it out, i'll keep working out some bugs so the angle is equal to the direction of force. thought id post my current findings though in case it helps

  • you can use clamp(angle,minvalue,maxvalue) see if that works min value for u wold be 180-car.angle max wold be 180 or 90

    the expresion original is clamp(number,min,max) but i added the angle cause you want the rotation to be towards surtain angle in order to stop it to go pass it... you job now is to find that specific angle at any time and place of the car on the game... if its in a circular race.. you have to find the radius position of the car... and find the left and right position of it and clamp on left and right turn the specficific numbers

    so you will have to store the angel of the car one time to know what was the last angle of the car... forgot to mention... so when A or D was pressed save the angle of car 1 time in a variable local or global.. then use that one to determine the min and max rotation

  • I think the way I have set my game up clashes with this method.

    https://www.dropbox.com/s/ug3qdieh4lvh9 ... .capx?dl=0

    that is my .capx while I try both your suggestions, thank you.

  • yo!!

    ok, so if you have a

    (physics on the car btw)

    Is In touch event-------------------apply force to position( depends on the size of your car) touch.x touch.y

    every...(i did 0.00009)seconds-------and i did rotate 5 degrees towards angle

    needs ALOT of tweaking... but this gives the illusion force is being applied to the car and it accelerates to the desired position with it's speed being affected by motion

    slap in some immovable physic barriers for the track and boom!, you could even have some AI cars that have check points to drive to. loads of examples of these so enjoy

    try it out, i'll keep working out some bugs so the angle is equal to the direction of force. thought id post my current findings though in case it helps

    okk so I've tweaked around with this and it sort of works, well it works on its first time and then any other destination is just unpredictable which I think it is dependant at what angle it is at, for example turning different ways, so I'm not sure how to fix this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i made this as a game, works ok... it does seem a bit slippery slidy ice floor though...

    i added an else clause

    my code exactly is:

    on start of layout - gravity set to 0

    every 0.00009 seconds

    -----is in touch-rotate 5 degrees towards touch x,y

    -------------------- Apply physics force 5 towards touch x,y at image point 1 (the rear)

    -----Else- (car)set angle to car.angle degrees (this stops the car spinning randomly)

    the physics for friction is all u dude

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