Truck with a trailer

sparkaniasparkania Member, PRO Posts: 300
I have read a few posts including http://forums.gamesalad.com/discussion/33288 on how to constrain 2 actors together.. but for some reason the options are not there in my constrain: --- to ---.
When on the Truck actor
I can constrain self.position.x to self.position.x
and y to y

when on the Trailer actor, I don't have the option to constrain to the Truck.. it's really buggin me.. Help?
«1

Comments

  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    As far as I know, you can not directly set up a constrain like that in the prototype actor. You would either need to have an attribute that will track the position of the truck, then have the trailer constrain to that value, plus or minus the distance in front/behind. Another option would be to place both actors in the scene, and unlock the trailer actor. Once you do that, with the constrain attribute you can navigate to Layers>(Layer the truck is on>Truck>Position>X/Y

    The second method will become tricky if you have many scenes, because you would need to add new rules to every unlocked actor separately.
  • sparkaniasparkania Member, PRO Posts: 300
    ok.. so how would I go about making this tracking attribute?
  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    Typically, make a real global attribute. Have the ruck actor constrain that attribute to its position. Then, in the trailer, have it constrain its position to that attribute, plus or minus the distance it needs to be from the truck.
  • sparkaniasparkania Member, PRO Posts: 300
    I just tried your suggestion, it moved the trailer to the truck's starting point, but when the truck moved, the trailer stayed where it was.. I'll try more in the morning.. Thanks
  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    Hmm. The only thing I could think would do that is if you accidentally used Change Attribute instead of Constrain at some point.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Truck:
    Constrain Attribute game.TruckX (real) to self.position.X
    Constrain Attribute game.TruckY (real) to self.position.Y

    Trailer:
    Constrain Attribute self.position.X to game.TruckX
    Constrain Attribute self.position.Y to game.TruckY

    This will force the trailer to stay at the same x/y as the truck. Keep in mind that in GameSalad, x/y coordinates refer to the center of the actor. So if you want the trailer to be behind the truck instead of on top of it, you'd need to do something like:

    Constrain Attribute self.position.X to game.TruckX-100 (assuming your truck has 100 width).

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

  • sparkaniasparkania Member, PRO Posts: 300
    edited December 2012
    ok.. there has to be something that you guys know that I am missing. so I will put out here what I am doing because something is still not happening..

    1. I select on the stage the actor I labeled 'Truck'.
    2. I create 2 new 'Real' attributes. TruckX and TruckY and leave them at 0.

    3. Then I go to the Backstage and drag in 2 Constrain Attribute blocks.
    The first one, I select
    constrain: Attributes>Truck>TruckX =(self.TruckX)
    to: Attributes>Truck>Position>X =(self.position.x)
    Second one
    constrain: Attributes>Truck>TruckY =(self.TruckY)
    to: Attributes>Truck>Position>Y =(self.position.Y)

    so far so good

    4. I select on the stage the actor I labeled 'Trailer'
    drag in 2 Constrain Attribute blocks
    The first one, I select
    constrain: Attributes>Trailer>Position>X =(self.position.x)
    to: Attributes>.... what? I do not have an option to pick anything labled Truck nor are the TruckX nor TruckY in the 'Game' list.
    Second one
    constrain: Attributes>Trailer>Position>Y =(self.position.y)
    to: Attributes>.... what? I do not have an option to pick anything labled Truck nor are the TruckX nor TruckY in the 'Game' list.

    is it something I should type into the fields or am I limited to that which the selection widows offer?
    So like I said, I am missing something. Something that you may understand as 'Duhh' but I am still learning and there is something I am not catching..

    I do understand that the constraint will lock to the middle of the actor and that +/- must be entered to land it exactly where I want it to appear..
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    You need to make your attributes global rather than just for the truck actor.

    A global/game attribute can be accessed by any actor, an actor attribute can only be accessed by that actor (unless you start unlocking your actors).
  • sparkaniasparkania Member, PRO Posts: 300
    So not on the actor, create TruckX for example under the Game or the Scene?
  • sparkaniasparkania Member, PRO Posts: 300
    Got it.. I was creating the TruckX attribute in the wrong place...
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    "Got it.. I was creating the TruckX attribute in the wrong place..."

    Yep! It needs to be a game attribute.
  • sparkaniasparkania Member, PRO Posts: 300
    soo... moving forward..
    Just to be clear, I am creating an overhead-view driving game.
    I have the Trailers x and y constrained to the Truck's x and y via the 2 (real) attributes.. BUT.. now they move like they are synchronized swimmers.. the trailer is not being.. "Towed" per say, nor does it rotate static to the trucks movements. it is staying in the same position relative to the truck. So I added a third constraint for the rotation, setup similar to the TruckX and TruckY.. but now when I turn, the truck rotates as it should but the trailer mirrors that same activity..

    is there a way to static attach 2 actors? to make one rotate with the other, not just mirror the rotation?
  • sparkaniasparkania Member, PRO Posts: 300
    edited December 2012
    in other words, If I had an actor which looked like a clock face. and I constrain a smiley actor to the 12 on the face. currently with the above info, if in the game I control the clock to rotate left, the clock will rotate but the smiley will stay put. If I turn the clock left 90 degrees so that the 3 is now facing up, the smiley will now be covering the 3, and remain stationary in relation to the x/y center of the clock actor.. How do I make it so that I constrain it to stay over the 12?
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    "soo... moving forward.. "

    No thanks.

    : P
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    One way is to add a rotate to position behavior on the trailer and use game.truckX and game.truckY as the position to rotate to. This is a bit sloppy and there's a better method using vectorToAngle. I believe you constrain the self.rotation of the trailer actor to vectorToAngle(game.truckX-self.position.X, game.truckY-self.position.Y).

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Now that I think about it, you're gonna need some trig to get this working... and that's not my strong point, sorry.

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

  • sparkaniasparkania Member, PRO Posts: 300
    gonna try the vector approach. I have a thought on how to fake the trailer by making 4 small blockers (if I can get them to static attach to the rear of the truck) and arrange them like a square doughnut, then putting another small blocker in the middle and attach it to the trailer. have the blockers only collide with each other.

    Then add yet another actor as the 'trailer wheels' and attach them accordingly.. put a little drag on the wheels and whammo.. I only need to get constrained items to keep their position with relation to the rotation of it's parent actor..
  • sparkaniasparkania Member, PRO Posts: 300
    Rotate to position did not work as the trailer is already constrained to the truck, so there is no change in activity. the trailer is pointed at the truck already
  • sparkaniasparkania Member, PRO Posts: 300
    well I tried the blockers idea and set the ring of blockers to the truck, and the sphere blocker in the middle of the ring.. it tows the trailer but does not effect the trailers rotation.. basically, when I turn the truck, the trailer goes along with it but does not go behind it.. it stays horizontal..
  • sparkaniasparkania Member, PRO Posts: 300
    something about constraining x/y kills the rotation qualities of a collision. but adding a rotation constraint just makes the second actor rotate on it's own center mirroring the holder of the constraint.. I might just be done yelling at my screen for the night....
  • SocksSocks London, UK.Member Posts: 12,822
    Like tatiang said, trigonometry is your friend here, you are basically trying to create a joint, trigonometry is the only viable way.
  • sparkaniasparkania Member, PRO Posts: 300
    elaborate please. I do not have a suitable formula for calculating a change in x and y position as it relates to the rotation of another object. If you have one, I have my Ctrl-C ready!
  • SocksSocks London, UK.Member Posts: 12,822
    "elaborate please"

    What's in it for me ?

    : )
  • sparkaniasparkania Member, PRO Posts: 300
    a reeeeally big thanks!!! actually my wife would be happy because then I would get off the computer and go shovel snow...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Here is a thread that looks at a similar thing. There is a demo file to download. Change the mouse body to a cab and the tail to a trailer.

    http://forums.gamesalad.com/discussion/45895/pseudo-joint-and-rotation-problems
  • sparkaniasparkania Member, PRO Posts: 300
    man that's quite a set of blocks.. can't imagine the bald spot that must have made.. I think thats what I am looking for to do my trailer hitch
  • sparkaniasparkania Member, PRO Posts: 300
    would you mind if I transcribe that which I learned from that download to this thread. I dont think many would find that as an answer while searching the forums. When I search for building a Truck with a Trailer, I dont think a mouse with a tail will be in my keywords.. :D
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    But this discussion thread is titled "Truck with a Trailer" so I think it will show up search results. But sure, if you want to annotate things a bit, why not?

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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    man that's quite a set of blocks.. can't imagine the bald spot that must have made.. I think thats what I am looking for to do my trailer hitch
    I categorically deny that GameSalad made me go prematurely bald!

    However, to be on the safe side perhaps we should ask SSS if we need to log a bug report about this.

  • sparkaniasparkania Member, PRO Posts: 300
    just wanted to check.. some people don't like it when their work is told by others...
Sign In or Register to comment.