Constrain actor in front of another actor (need cos and sin help pls)

micksolomicksolo Member Posts: 264
edited January 2012 in Working with GS (Mac)
Hi, I have a car in a top down game, i want to constrain another actor directly in front of that car no matter which way the car is facing.

Anyone got a simple cos and sin formula to help me get started please?

Comments

  • CloudsClouds Member Posts: 1,599
    How simple do you want your 'cos and sin formula' to be ?
  • micksolomicksolo Member Posts: 264
    i want it to work haha.
  • tutysestutyses Member Posts: 134
    it would be constraining X and Y of the car position and taking the angle of rotation of the object
    Then take the Half of the size in x and y , you have to use Cos for x and Sen for Y

    Constrain actor pos x to Car pos x +cos angle *Half size car in that axis
  • micksolomicksolo Member Posts: 264
    sorry i don't quite follow, i think i tried implementing as you suggested but its just constraining right on top of the car rather than in front.
  • tutysestutyses Member Posts: 134
    give me a minute i will try to show you
  • micksolomicksolo Member Posts: 264
    thanks man
  • tutysestutyses Member Posts: 134
    in the car Actor, create 2 behavior constraining X and Y position to 2 global Atributes , carx and cary
    in the object which has to follow the front of the car , make a constrain attribute like this
    constrain position x to Carx +(cos(angle)*HSX)
    Where carx is the x position of the car, angle is the current rotation angle of the car and HSX is half the size on the x axis
    Then the same for the Y, but using sin
    constrain position y to Cary +(sin(angle)*HSY)
    where Hsy is half size on the Y
  • micksolomicksolo Member Posts: 264
    thanks man

    HSY is that carposx / 2, or half the size of the car itself?
  • tutysestutyses Member Posts: 134
    i never said it was half the position ,its half the SIZE
    if your car is 32x16 then
    Hsx 16
    hsy 8
  • micksolomicksolo Member Posts: 264
    ok thanks a lot...its not quite working as it should but its a step closer. My game is using landscape mode so i think i need to flip the cos and sin around, which works better but still not perfectly. thanks a lot for your help
  • tutysestutyses Member Posts: 134
    if your project is not too big, upload it so i can see it , but tomorrow because its 9 am here and i m going to sleep now
  • Rob2Rob2 Member Posts: 2,402
    give us a minute :)
  • Rob2Rob2 Member Posts: 2,402
    Something I did ages ago - sloppy and unlocked actors etc but some notes !! Use arrow keys to move
    Tank Rotate
    see:- http://en.wikipedia.org/wiki/Pythagorean_trigonometric_identity for theory
  • MotherHooseMotherHoose Member Posts: 2,456
    @Rob2 … Tank Rotate … functions so beautifully!

    thanx!

    @};- MH
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @Rob2
    There are some real gems in that demo:
    1) extremely easy to follow positioning formulas
    2) intuitive rotation of the two constrained objects
    3) a really great forward/backward direction control system I'd never even dreamed of! (I will be extremely embarrassed if everyone knew how to do that but me.)

    Thanks for sharing it!
    RThurman
  • Rob2Rob2 Member Posts: 2,402
    Cheers folks - that really means alot :)
  • micksolomicksolo Member Posts: 264
    Thanks a lot for everyone's help in this thread. The tank demo was great too!

    I finally worked it out using bits and pieces from everyone's solutions, here are the final formulae I used to constrain an actor in front of a car

    The rules for the constrained actor
    constrain self.pos.x -> Car.Pos.X +(cos(Car.Rotation+90)*150)
    constrain self.pos.y -> Car.Pos.Y+(sin(Car.Rotation+90)*150)

    the Car rotation=90 was added because initially the actor is constrained to the right of the car (if the car is pointing up) so added the +90 and it constrains in front of the car. The 150 at the end you can change to any number, it just moves the actor closer or further away but 150 seems to work well about 1/3 of a scree in front of the car.

    Thanks again to everyone that helped out!
Sign In or Register to comment.