Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sliding rear end in car game - 2D - Based on Baxslash's code

Author
Message
SirWinston
7
Years of Service
User Offline
Joined: 25th Aug 2016
Location:
Posted: 25th Aug 2016 04:25
Hi guys,

Does anybody know how to make the rear end (or tyres) of a 2D car slide? I'm basing my initial physics model on the code Baxslash kindly provided back in 2012 (see below). I've tried every single relevant sprite and physics command (e.g. SetSpritePhysicsFriction, set the sprite's mass and COM), but the rear wheels just trundle along behind. The only permanent change I have made to Baxslash's code is to apply the setSpritePhysicsImpulse to the rear wheels, not the front, because I want to simulate a rear wheel drive vehicle.

BTW, thanks Baxslash for the code. Figuring out those physics calculations myself would have taken forever!



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th Aug 2016 08:16 Edited at: 25th Aug 2016 08:19
its skid not the same as Sliding?
i think its the part with the shift key where the tires lost contact.


i believe the problem with 2d box physics in agk is that you need friction at overlapped sprites, ground + wheels.
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th Aug 2016 11:11
The restrictLateralMovement function "amount#" parameter allows you to make the car skid more. Use a low value (around 0.0) for lots of skid and a high value (around 1.0) for no skid. Glad to see someone using it
Using AppGameKit V2 Tier 1
SirWinston
7
Years of Service
User Offline
Joined: 25th Aug 2016
Location:
Posted: 26th Aug 2016 05:15
Thanks for the answers guys. Baxslash, the only problem with decreasing restrictLateralMovement is it reduces the turn radius, which actually rewards sliding. That's why I think a few people said that it felt a bit "cheaty".

I'll try to create a section of track as a sprite, and see if I can use SetSpritePhysicsFriction to get the desired outcome. Will keep you posted.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 26th Aug 2016 08:46
i think u can use this restrictLateralMovement function to get the side force if your car drive a curve.
u need a threshold value from static friction go into sliding friction.
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
SirWinston
7
Years of Service
User Offline
Joined: 25th Aug 2016
Location:
Posted: 26th Aug 2016 11:27
Thanks Markus, I'll give that a go tomorrow.

I did make some progress! I bought the AGK2 tutorial guide, and a section in that referred to a sprite's rotation point. I did some more digging, and discovered that SetSpriteOffset positions the object's rotation centre. I had previously added mass to all of the vehicles's sprites, and 90% of the mass was assigned to "car.body". So I repositioned car.body's sprite offset to in between the front wheels, and instantly the rear of the car started sliding under braking!

Tomorrow, I'll have a play with the restrictLateralMovement function, see if I can get it to "break away" under excessive lateral load (e.g. exit oversteer, whole car sliding). Also, I'll do some playing with SetSpritePhysicsCOM, see if I can simulate a shift in COM under braking and acceleration. If I can achieve these, I'll have an engine to build a game on!

One question: Is there a way to make the car sprite(s) move "on" a static sprite, and apply friction alterations? Or do I have to use GetSpriteInBox and do it from there?

Thanks for your help guys. I really appreciate it.
SirWinston
7
Years of Service
User Offline
Joined: 25th Aug 2016
Location:
Posted: 1st Sep 2016 09:34
Update: I'm just about happy now. Hopefully the following will help anybody trying to do a similar thing.

I have:

1. Tweaked the physics scaling, striking a good balance between speed, base acceleration, push from the physics impulse and turning circle
2. Added and modified the centre of mass (COM) and restrictLateralMovement settings according to the current controller action. For example, under braking I have significantly moved the COM forward, to simulate the difficulty changing direction under brakes, and set the rear tyres to be loose.
3. Tweaked where the vehicle weight, to increase the turn radius, particularly under acceleration (without making it feel like a boat)

Still left to try:

- Modifying the restrictLateralMovement function to allow the car to "break away" more when the physical limit is being exceeded
- Adding and modifying the sprite friction settings as the car moves around on a sprite track.

Login to post a reply

Server time is: 2024-04-25 17:04:25
Your offset time is: 2024-04-25 17:04:25