How do I limit rotation?

Get help using Construct 2

Post » Fri Sep 11, 2015 3:36 pm

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.
B
7
S
1
Posts: 54
Reputation: 527

Post » Fri Sep 11, 2015 5:21 pm

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 :)
Last edited by Aher0 on Fri Sep 11, 2015 5:36 pm, edited 1 time in total.
B
9
S
3
Posts: 102
Reputation: 987

Post » Fri Sep 11, 2015 5:31 pm

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
B
77
S
23
G
69
Posts: 1,353
Reputation: 43,960

Post » Fri Sep 11, 2015 5:48 pm

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.
B
7
S
1
Posts: 54
Reputation: 527

Post » Fri Sep 11, 2015 10:50 pm

Aher0 wrote: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.
B
7
S
1
Posts: 54
Reputation: 527

Post » Sat Sep 12, 2015 1:46 pm

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
B
9
S
3
Posts: 102
Reputation: 987


Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 32 guests