A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Help with towing a trailer

Hybrid View

  1. #1
    Junior Member
    Join Date
    Dec 2001
    Posts
    10

    Help with towing a trailer

    Hi guys...

    Hope you can help me figure out something that's driving me nuts!

    Currently working on a little game that involves lorries/trucks. I've got near enough everything sorted except for one thing...getting the lorry cab to pull the trailer. How on earth do I do that??? The trailer needs to follow the cab around realistically pivoting at the trailer's rear wheels and the trailer/cab connection.

    Can anyone point me in the right direction or, even better, give me a peek at the actionscript that would sort this out?

    Thanks for your help!
    Spu
    Error 745a - Bad or Missing Keyboard, press F1 to continue

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    wouldn´t that involve IK (inverse kinematic) ?
    back in the days of GTA2 I remember some slobby implented attempt for doing that.


    in any case it would mean that the trailer always points towards a spot of the truck (eihter the pivot itself or an offset pivot of that one). And with every move of the Truck the trailer would have to move with the truck within a constraint.
    Is this even what you are searching for?

  3. #3
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    maybe this can help?
    mmm signature

  4. #4
    Junior Member
    Join Date
    Dec 2001
    Posts
    10
    Yep, it's exactly what I'm after. To be honest I never knew anything about IK before your post but I've done a bit of reading on it now and it seems like the way I need to go. Thanks a lot!

    Does anyone have any example code by any chance???

    Thanks
    Error 745a - Bad or Missing Keyboard, press F1 to continue

  5. #5
    Junior Member
    Join Date
    Dec 2001
    Posts
    10
    ChaseNYC - Thanks for the reply. Yep, I'd seen that when I was searching around for an answer. Although that's what I wanted to achieve, it did actually say how to do it.
    Error 745a - Bad or Missing Keyboard, press F1 to continue

  6. #6
    Senior Member walnoot's Avatar
    Join Date
    Apr 2005
    Posts
    751

  7. #7
    Junior Member
    Join Date
    Dec 2001
    Posts
    10
    Thanks for the links, Walnoot & trogdor458.

    I've read through all of the info you guys have given me but *still* having trouble putting it into practice. It's the ability to control it with the keyboard rather than the mouse that's giving me grief.

    I've attached what I've got so far but the movement is wrong. Keys UP & DOWN should make it go forward and backwards not increase/decrease the Y position. The same goes for LEFT & RIGHT keys.

    Anyone get an ideas, please?

    Thanks to everyone for your help!
    Attached Files Attached Files
    Error 745a - Bad or Missing Keyboard, press F1 to continue

  8. #8
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    i had made something in class (due to boredom) that is similar to what you ask, not sure if it uses inverse kinetics though, i never read up on the topic
    http://trogdorffe.tripod.com/attempted_optimization.swf
    pardon me if its slow/poor looking, i made it kind of messy, and this is my attempted optimization

    basically i find the dircetion one chain link is relative to another, and whilst keeping the same direction, set the distance to a constant
    all the while, adding the _x and _y differences to the x and y speeds (later on during my boredom, I also distributed this energy between the two links evenly, to simulate action/reaction pairs, didnt seem to change much though)

    virtual chain!! got a better looking one on my comp that has a bevel effect added

  9. #9
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    you mean you want the car to move correctly? because that should be easy enough

  10. #10
    Junior Member
    Join Date
    Dec 2001
    Posts
    10
    Yep, the car/cab to move like a normal car would and the trailer to follow. I've tried using the code I was using before I added the trailer that rotated the car but that then screwed up the movement of the trailer.
    Error 745a - Bad or Missing Keyboard, press F1 to continue

  11. #11
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    use this movement instead:

    if (Key.isDown(Key.LEFT)) {
    ypos+=Math.sin((seg0._rotation-90)*Math.PI/180)*5;
    xpos+=Math.cos((seg0._rotation-90)*Math.PI/180)*5;
    }
    if (Key.isDown(Key.RIGHT)) {
    ypos+=Math.sin((seg0._rotation+90)*Math.PI/180)*5;
    xpos+=Math.cos((seg0._rotation+90)*Math.PI/180)*5;
    }
    if (Key.isDown(Key.UP)) {
    ypos+=Math.sin((seg0._rotation)*Math.PI/180)*5;
    xpos+=Math.cos((seg0._rotation)*Math.PI/180)*5;
    }
    if (Key.isDown(Key.DOWN)) {
    ypos+=Math.sin((seg0._rotation-180)*Math.PI/180)*5;
    xpos+=Math.cos((seg0._rotation-180)*Math.PI/180)*5;
    }
    note how its not car movement, but it seems to be what you asked

  12. #12
    Junior Member
    Join Date
    Dec 2001
    Posts
    10
    Thank you so much, mate! That's what I needed....I think.

    Thanks again!
    Error 745a - Bad or Missing Keyboard, press F1 to continue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center