Math help with following position and rotation.

JohnPapiomitisJohnPapiomitis Member Posts: 6,256
edited November -1 in Working with GS (Mac)
Hey guys,

I have a actor thats set up, and i want to have forth other actors on each side that rotate and move with the original actor.

This is the best way to describe it.

http://gamesalad.com/game/2076

On the actor i want the other ones to spin around, i have game attributes playerx,playery, and player rotation, constrained to the actors x,y and rotation.

Then for the actors i want to spin with them i have the following rules.

Constrain rotation to: player rotation.

Constrain self position x to: 135*cos(playerrotation)+player x

Constrain self position y to: 135*sin(playerrotation)+player y

Now that works perfect, the only problem i have is trying to set where its starts from.

As you see in the link i posted, theres the one object(chainsaw in demo) that rotates around the center depending where it is. I want to put ones on each side, so itll be like the demo but a chainsaw on each side for a total of 4, not just one.

Now if i mess with the cos and sin, or if i put an offest in my equation or in the player x and y attributes to change where it starts from and which side it sticks to, it doesnt follow the correct path like the first one.

Im useally really good with math, but for some reason this has me stumped. damn trig :(

If anyone could help i would appriciate it sooo much!!

Thanks a bunch in advance guys.

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    bump before i throw my computer out the window...
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey John,

    This will do it for you. This is the code for each of the chainsaws:

    Constrain self position x to: 135*cos(playerrotation)+player x
    Constrain self position y to: 135*sin(playerrotation)+player y
    Constrain rotation to: playerrotation

    Constrain self position x to: -135*cos(playerrotation)+player x
    Constrain self position y to: -135*sin(playerrotation)+player y
    Constrain rotation to: playerrotation

    Constrain self position x to: 135*cos(playerrotation + 90)+player x
    Constrain self position y to: 135*sin(playerrotation +90)+player y
    Constrain rotation to: playerrotation

    Constrain self position x to: -135*cos(playerrotation + 90)+player x
    Constrain self position y to: -135*sin(playerrotation + 90)+player y
    Constrain rotation to: playerrotation

    However, you should really test that on an older device. You'll need 15 Constrain Attributes to pull that off, which will murder your FPS...
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    firemaplegames said:
    Hey John,

    This will do it for you. This is the code for each of the chainsaws:

    Constrain self position x to: 135*cos(playerrotation)+player x
    Constrain self position y to: 135*sin(playerrotation)+player y
    Constrain rotation to: playerrotation

    Constrain self position x to: -135*cos(playerrotation)+player x
    Constrain self position y to: -135*sin(playerrotation)+player y
    Constrain rotation to: playerrotation

    Constrain self position x to: 135*cos(playerrotation + 90)+player x
    Constrain self position y to: 135*sin(playerrotation +90)+player y
    Constrain rotation to: playerrotation

    Constrain self position x to: -135*cos(playerrotation + 90)+player x
    Constrain self position y to: -135*sin(playerrotation + 90)+player y
    Constrain rotation to: playerrotation

    However, you should really test that on an older device. You'll need 15 Constrain Attributes to pull that off, which will murder your FPS...

    Thank you so much! Yes ill definetly test on my 2nd gen first but know i realize what i was doing wrong with getting them to switch there starting position. Thanks again my friend!
Sign In or Register to comment.