Stuck on some sort of formula needed

JamesZeppelinJamesZeppelin Member Posts: 1,927
edited November -1 in Working with GS (Mac)
Ok so here is my issue.

I have this lady bug that moves around much like the way a ball does in labyrinth game.

However i want him to point the direction he is going.

i attached rotate to angle and figured just pointing in one of four directions would be ok.

It looked fine on the mac simulating the moves with the arrow keys however when i put in on the iphone he just gets kinda squirrelly. seems to point left and right ok but up and down dont work so well

I was wondering if there is some sort of formula that could be put in to make him always point in the direction he is moving.

I know thats alot

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    I imagine you could have 4 integer attributes - position1X position2X position1Y position2Y

    Every .1 seconds
    Change self.position2X to self.position1x
    Change self.position1X to self.position.X
    Change self.position2Y to self.position1Y
    Change self.position1Y to self.position.Y

    Constrain self.rotation to VectorToAngle (self.position1X-self.position2X , self.position1Y-self.position2Y)

    I just thought this up. Haven't tried it. But the idea is that every 0.1 seconds you are figuring out the angle between the point on the screen at the beginning of the 0.1 seconds and at the end of the .1 second interval.
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    Cool I'll mess around with it.
    I haven't really got my head around vector to angle yet but I'll plug ghat in and see what happens

    thanks
    I'll report back later tonight
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    Im not quite sure how to write this part:

    Constrain self.rotation to VectorToAngle (self.position1X-self.position2X , self.position1Y-self.position2Y)
  • ORBZORBZ Member Posts: 1,304
    rule: when linearVeloctyX not equal to 0 or linearVeloctyY not equal to 0 then:

    constrain attribute self.rotation = vectorToAngle(self.motion.linearVelocityX, self.motion.LinearVelocityY)

    done.
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    thanks!!!!

    I think i follow that

    Ill plug it in and see what happens
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    Holy crap thats awesome

    His turning speed even keeps up with his movement speed.

    I noticed it also helps because when you bump into a wall it snaps his towards teh direction you are going to make it a little easier to control!!

    thanks man
  • ORBZORBZ Member Posts: 1,304
    np :)
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Glad that worked!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    What did it do to the fps? (with the timer and the constrain)
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    i used the thing orbs suggested

    there was no timer invlolved

    I actually didnt even need to use the velocity rule he suggested.

    the only thing i used was
    constrain attribute:
    self.rotation = vectorToAngle(self.motion.linearVelocityX, self.motion.LinearVelocityY)
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    very cool! I'll have to try that.
  • rebumprebump Member Posts: 1,058
    The velocity rule may help in performance down the road when more is going on in the scene...no need to constrain if things aren't moving (and if GS' rule parsing is working properly ;-p ).
Sign In or Register to comment.