Help with car physics?

TWEAmazingAppsTWEAmazingApps Member Posts: 219
edited August 2012 in Working with GS (Mac)
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
«1

Comments

  • ironDanironDan Member Posts: 148
    If you can post a video of what you have or the source code then we can probably get it to do what you want. It's hard to help without seeing what you are doing.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    Ok Ill do that.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    Ok here are some photos of the coding. I am working on making a video.
    http://www.4shared.com/folder/yVUgEQeJ/_online.html
  • HymloeHymloe Member Posts: 1,653
    You have to login to that site to download those files. I don't want to do that.
    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



  • OskarDeveloperOskarDeveloper Member Posts: 533
    edited November 2012
    Use dropbox for the file. Put the zip file in your dropbox public folder and then copy the public link, paste the link in this thread. That way, if anyone press the link the download will start.
  • HymloeHymloe Member Posts: 1,653
    Dropbox works for me, I have it installed.

    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. :)
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    You could make it so that the car accelerates only when a boolean (go or something like that) is true and when you press the button/key to make it turn, it sets the boolean to false and you enter the code to rotate the car. Would that work?
  • HymloeHymloe Member Posts: 1,653
    It's not really the issue, but thanks for trying @Utveckla_Games.

    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?
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    edited December 2012
    Ok @Hymloe so let me make sure I'm right on this, the car image rotates but when it you press the button it still goes forward right? :-?
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    Nope nevermind @Hymloe I think I got it. Haha sorry I'm a little slow today.
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    Ok so to keep updating something you use a constrain attribute. Ill have to look again but there should be some actor or game attributes that will help fix this.
  • HymloeHymloe Member Posts: 1,653
    Thanks @Utveckla_Games,

    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! :)



  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    Try using move instead of accelorate. Unless you want it to continually get faster. But maybe you could use move and for the speed use an attribute called speed and use timers to continually add speed ever 3 seconds or so... Get what im saying?
  • HymloeHymloe Member Posts: 1,653
    Sort of. :)
  • HymloeHymloe Member Posts: 1,653
    Currently, my cars works using the attributes... I constrain all of these...

    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? :)
  • BoyGeniusStudiosBoyGeniusStudios Member Posts: 92
    I actually need an answer for this too. I am making a dolphin olympics styled game, but I need the dolphin to be able to turn after hitting the water.
  • HymloeHymloe Member Posts: 1,653
    Any physics wizards out there?
  • BoyGeniusStudiosBoyGeniusStudios Member Posts: 92
    edited December 2012
    I think I may have found the solution in an old post from mangaroo, but I am not at my computer to try it, he said "try constraining linear x motion to 0 while linear y motion is not equal to 0"
  • HymloeHymloe Member Posts: 1,653
    That sounds.... um... not very useful. :)
    But maybe it makes more sense in context.
  • HymloeHymloe Member Posts: 1,653
    If you want your actor to just snap to going straight up, left, right, or down, this whole problem would be quite easy to solve. And maybe that's what you're trying to do. In which case, your suggestion might make sense, for sure.

    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.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @Hymloe Hey I know the deal with your car problem. I kinda put a stop on my own project but this is the theory I was going to implement that will work. The reason your car isnt turning correctly is this... Picture your actor as a engine and wheels... And the car..well the car... Whats happening is your wheels and engine is constrained in the middle by default. So when you turn your really turning from the middel of your car.. So hence the fake movements and slides.. But if you put the engine and wheels relevant to the front of the actor. Then It will turn as if the weight and power is coming from the front so it will force the actor to turn accordingly like a car would. Hope this helps you :D
  • HymloeHymloe Member Posts: 1,653
    edited December 2012
    Thanks @TWEAmazingApps, you're right about that. But I'm not sure how I'd set up this sort of "car simulation" in Game Salad, wih a car body, separate wheels attached to axles, and steering properly using a physics simulation... But yes, that'd help!

    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. :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    The section on Curves at this site seems to explain how this might work in GameSalad: http://www.asawicki.info/Mirror/Car Physics for Games/Car Physics for Games.html

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HymloeHymloe Member Posts: 1,653
    Thank you so much @tatiang, that is a fantastic article. I think I'm getting somewhere. Thanks for all the great advice and ideas, guys! :)
  • HymloeHymloe Member Posts: 1,653
    I've been trying to build my own car physics system using the MOVE rule.

    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.

  • HymloeHymloe Member Posts: 1,653
    edited December 2012
    I FINALLY got my car physics, controls & handling feeling good.

    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.

  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    Nice congratz!!! That Great!!!! I am glad you found the solution!! I also had the same issue with move attribute. Its like I kinda figured "move" is just a stripped down version if you dont want to mess with physics. I use it mostly for characters with a walking animation mainly like FF Tactics style characters but other than that I hardly ever find myself using move. But Thank you for posting back the solution to the problem. I greatly appreciate it and I am sure others will and are too! when then check this out. :D

    -Cheers!
  • JayteeJaytee Member Posts: 79
    @Hymloe
    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
  • HymloeHymloe Member Posts: 1,653
    edited March 2013
    My car system has a lot of complexity in it, and it still doesn't work entirely to my liking. It's difficult to explain, although I have tried to explain it somewhat in a few posts on these forums, I think (see above). But there's heaps of fiddly little rules and nested behaviours about steering, acceleration, how the controls work in different situations, like if the car is moving forwards or backwards, switching car attributes around (such as the amount of drag), depending on how fast the car is going, or which way it is facing compared to it's actual movement vector.

    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!

  • DepressedPandaDepressedPanda Member Posts: 215
    This is completely unhelpful but I feel obligated to say it anyway.... Great job on the game thus far. Looking like a real winner!
Sign In or Register to comment.