Help with car physics?
TWEAmazingApps
Member Posts: 219
Hello
I am trying to make a car trun left and right like it dose in GTA Chinawars but its seems like when I make it turn the car will still keep moving forward and then start to slightly turn. But I want it to be fast cuts left right like it dose in the GTA game. Dose anyone have any tips? thanks
I am trying to make a car trun left and right like it dose in GTA Chinawars but its seems like when I make it turn the car will still keep moving forward and then start to slightly turn. But I want it to be fast cuts left right like it dose in the GTA game. Dose anyone have any tips? thanks
Comments
http://www.4shared.com/folder/yVUgEQeJ/_online.html
Could you put them somewhere else where they can be downloaded at the click of a button?
I'm actually trying to solve this same problem, pretty much.
And rather than start a new thread, I'll continue along here, and maybe we can help each other with a similar solution...
My problem is that my car feels like a spaceship in frictionless space.
I have it "thrusting" in the direction that's it's facing. So if I rotate the car and accelerate again, it eases towards going in that direction.
Using drag, the car does slow down on it's own, and I have it slowing down much more dramatically if the car is rotated away from the direction it's moving.
It feels kind of cool in a dirt-rally style driving sense. But the steering is not nearly as responsive as it should be. I want the car to actually move towards the way it's facing, without having to "thrust" in that direction.
This is how it works in my case:
When the player presses ACCELERATE, I use the Accelerate behaviour to say "Accelerate in direction 0, using the actor's local coordinates". ie: move forwards.
That works fine.
If the player then steers left and right, I use Change Attribute: self.Motion.AngularVelocity, so the car itself rotates.
I'm somewhat happy with that... the car rotates, and I can then accelerate in that direction, but the car basically just keeps moving in the direction it was already going.
I want the car to change it's Linear Velocity X and Y whenever you steer, to be moving more-so in the direction that you're now facing. Without having to accelerate in that direction. (But I also want to allow for a bit of a sense of off-road handling, so I don't just want it to snap to the new facing angle).
I'm not sure what sort of Expression to use to update the car's Linear Velocity X & Y each time the player changes their facing direction (by steering).
Any suggestions would be great!
- Murray
The thread is a bit old (the original poster last posted in August), so we'll have to see if they make another appearance.
If anyone else has suggestions about how to make a car steer (while not accelerating), that'd be great.
My problem is that my car does not actually steer.
I can rotate my car, and accelerate in the direction the car is facing.
But if I just stop accelerating, the car keeps going in that same vector. If I then steer the car, it doesn't change the car's vector. It just rotates the graphic for the car.
I want the car to effectively keep updating it's vector depending on what way it's facing, even if I'm not accelerating.
And I can't figure out how to do it. Any ideas?
I've already released two games, and I've done a lot of work on this car handling. There's quite a bit going on in my car system. I'm just not sure how to update the Motion.Linear Velocity X & Y if the player steers while "rolling along".
I have it so you can steer, and "accelerate" in that direction. And like a rally car, it keeps sliding in whatever direction it was already going, and as you keep applying acceleration in your new facing direction, it "eases" towards that vector.
But it slides around more like a boat, or a spaceship, or a car on ice.
If I accelerate to 100mph, for example, then just drift along without accelerating, then steer the car, the car will rotate left and right (the image rotates), but the car itself just keeps sliding in the direction it was already going.
I want to be able to steer (rotate the car), and also have it physically steer in that direction.
I've made a video of where I'm at with the car. Any help would be really appreciated!
CarFacingAngle = self.Rotation
CarVelocity = magnitude (self.LinearVelocity.X, self.LinearVelocity.Y)
CarVectorAngle = vectorToAngle (self.LinearVelocity.X, self.LinearVelocity.Y)
CarFacingAngleVsVectorAngle = CarFacingAngle - CarVectorAngle
So I know which way the car is facing, I know how fast it's moving, and in what angle, and I know how dramatically different it's facing angle is from the way it's actually moving.
I just need to come up with an equation that uses these known attributes to adjust the LinearVelocity X and Y, so that the car's vector is adjusted towards the way that it's facing.
Can I manipulate Linear Velocity X and Y by using some snazzy Sin, Cos or Tan?
I think I could work something out, if I knew how to get an ANGLE, and get that back into Linear Velocity X and Y format.
I know that when the player steers left, I want to make the player's angle of movement move anti-clockwise. I'm just not sure how to "tell" this to my car!
While I DO KNOW how to record my car's current vector...
vectorToAngle (self.LinearVelocity.X, self.LinearVelocity.Y)
I don't know how to go back the other way.
I basically want to say to the car, "Hey, I know you're moving towards 90 degrees in the scene space, I want you to start moving towards 95 degrees, because the player has steered a bit to the left now." And to be able to "increase their angle of movement" over time, depending on player input and whatnot.
Does anyone know how to deduce a Linear Velocity X and Y from an Angle?
Or something like that?
But maybe it makes more sense in context.
But I'm trying to get my car to move around fluidly with nice physics, and update with a high-resolution solution.
Doesn't sound like anyone knows how to do it??? Bum.
I've changed tack, and started reworking the car to work differently.
I'm actually trying to just use the MOVE behaviour, and the ROTATE TO behaviour, and simplify the controls right down to use a single virtual DPad. I have it so that the car just snaps to face the way you're pointing on the DPad, and moves in that direction faster if you move the DPad further from the middle.
It feels really silly (not like a real car at all really), but maybe it's better to start with this different way of doing it, and then try to add some sense of realism on top of that. So thanks to @Utveckla_Games for suggesting I try it that way. Maybe it'll work out. Not sure yet!
Cheers.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
The problem I'm having is that if I'm always applying the MOVE rule to the car, it doesn't seem to respond well to the rest of the default Game Salad physics system.
Like, I think the MOVE rule overrides Game Salad's attributes for DRAG, for example.
So I can't control my car, giving it an appropriate MOVE Direction and Speed, while also wanting the car to have inertia and drag.
So I guess I have to try to build my own systems for inertia and drag into my variables I use for Direction and Speed. Tricky business, this.
I actually ended up almost back where I started, using the ACCELERATE behaviour. But instead, I'm now using the ACCELERATE TOWARD behaviour, and I tell the car to head towards an X offset at 100, and Y offset of 0, relative to the Actor itself. (This tells it to Accelerate Towards a point in front of itself).
I use an attribute called Accelerate_Offset for the Y Offset, and when the car is steering left or right, I set Accelerate_Offset to be 200, or -200, so that it accelerates towards the left or right a bit, as well as straight ahead.
I have the Accelerate Towards behaviour active at all times, and use an attribute called Accelerate_Current to define the acceleration rate. When the player is pressing the accelerator, I tell it to be 200. When the don't touch the accelerator, I set it to be
(magnitude(self.LinearVelocityX, self.LinearVelocityY)/4), thus having the car slow down gradually, but still maintaining it's natural amount of momentum. (This must be balanced against how much drag you have on the vehicle).
I then have a bunch of rules that change the self.DRAG amount for the car so that it slows down gradually if you let go of the accelerator button, and slows down really quickly if the car faces sideways.
For steering, I use Change Attribute: self.Motion.AngularVelocity (so that it rotates smoothly).
It took me several days, and 3 different approaches. I would not recommend using the MOVE behaviour if you want a car that feels realistic, because the MOVE behaviour overrides most of the basic physics system, disallowing the car to actually bounces off things, etc. Using ACCELERATE or ACCELERATE TOWARDS is much better for a sense of fluidity and realism.
-Cheers!
Can you tell exactly how you did it?? (You can also take a screenshot or upload a video) I can't seem to figure out how to get it working, it's like something is missing.
And if you want, it would be nice to see a video of your game. Just to see it in action
- Jaytee
It's really quite complex, and the best way to share all my work on it would actually be to make a template project, with the vast majority of my actual game removed, so as to provide an easy to use system for other people's games. And to let people pay me for the template, which would be much appreciated by me, for sure, as it's been something I've worked on for 6 months or so.
But to do that, I'd first have to improve it, make it work really nicely, make it as efficient as possible, and this isn't something I have time to do right now. It might be something I could do after finishing my game, by which time I'd have done all the improvements I can to the system overall.
My goal for such a template would be...
* Driving around in multiple vehicles (which take their values from a table, such as acceleration, top speed, health, turning rate, etc).
* Getting in and out of the car to run around on foot.
* Cars and human player character can use a range of weapons.
* Damage states for the vehicles. Vehicle is destroyed if health goes too low.
All of those features currently work in my game, but it's not highly polished, and not really ready to share with other people in a way that makes clear sense. I need to work on the UI for selecting weapons, representing how much ammo is remaining for each weapon, etc. It's got all the makings of a very useful top-down GTA style template.
I'll try to make a video of my game at some point in the future, maybe after I get some more official art in my game.
Cheers, and all the best!