Having trouble with steering wheel controls

Hi all! I am extremely new to GS and I am trying to teach myself the program by just stuffing around with projects. I've hit a roadblock while trying to make a simple racing style game where you gain points by passing other cars and not crashing. I'm trying to implement a steering wheel actor as a controller that controls the position of the racecar by constraining the self.position.x on the racecar to an attribute which conforms to the rotation of the steering wheel. And I've made the steering wheel rotation conform to the touch.position.x + touch.position.y touch1 if pressed inside the steering wheel. All this is fine but I've found that as soon as you "grab" the steering wheel it flips 180 degrees so it is inverted. I've solved this by adding +180 to the former equation, but as you can imagine this totally stuffs up the position of the racecar. How can I affect one equation without affecting the other ? I've already tried adding -180 to the corresponding equation on the racecar position x but it totally stuffs everything up once it goes past a certain angle. Any ideas?

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    By default GS measures rotation as 0° to 180° and then as you pass 180° (going counterclockwise) rather than going to 181° (and so on) it flips to -180° and then proceeds downwards back to 0° (going through -179° -178° -177° and so on).

    You can normalise these values (have them read 0° to 360° rather than 0° to 180° to 0°) by simply adding %360 onto the end of your rotation value.

  • OK i solved my own problem - but now i have a new one. The actors position.x moves perfectly with touch.x + touch.y, except that the player can move the car right off the sceen. How do I prevent this from happening?

  • Ah thanks for the tip - I've gone about it differently. But my above problem still stands

  • SocksSocks London, UK.Member Posts: 12,822

    @jamesritchie@gmail.com said:
    OK i solved my own problem - but now i have a new one. The actors position.x moves perfectly with touch.x + touch.y, except that the player can move the car right off the sceen. How do I prevent this from happening?

    All the answers will be somewhat of a guess as you are not showing us any of your code.

    You can set a minimum and a maximum value for any piece of maths by using the min and max functions.

    min(A,B) will return the smaller of the two values, so for example min(100,200) will give you 100.

    max(A,B) will return the larger of the two values, so for example max(100,200) will give you 200.

  • Never mind i fixed that too!

Sign In or Register to comment.