Actor's movement increases score

carlblanchetcarlblanchet Member Posts: 755
edited July 2012 in Working with GS (Mac)
What is the best way to have the score attribute increase with an actor's movement in all direction?
Please explain in depth.

Thanks! :D

Best Answer

  • Rob2Rob2 Posts: 2,402
    edited July 2012 Accepted Answer
    Constraining to mouse is just seeing the mouse position so no velocities calculated I'm afraid.

    You will have to do a series x,y samples and just calculate lots of magnitudes over time to get an idea of distance travelled if thats the way you want to go.

    OR...you could conceivably make a net of three actors (triangle) constrained to mouse place your actor inside and push it around with collision from the triangle - that would register velocity!! - but is a little bonkers :)

Answers

  • NovicaStudioNovicaStudio Member Posts: 174
    I am not quite sure why you would increase by distance, instead if it is an endless runner you are making, just trigger it by time: Every .1 Seconds change attribute game.score to game.score + 1

    If this isn't the answer you are looking for, please just say.
  • carlblanchetcarlblanchet Member Posts: 755
    @NovicaStudio
    I actually already have the score increasing with time, but I am also wanting the score to increase with the actor's movement on the scene, and yes it is somewhat of an endless runner game. :)
  • MotherHooseMotherHoose Member Posts: 2,456
    @ carlblanchet … how does the actor move?

    with touch?

    demo: http://www.mediafire.com/?f99nn7em6j39sbu

    image MH
  • MotherHooseMotherHoose Member Posts: 2,456
    edited July 2012
    wow … wouldn't post comment … just hanging …
    then window changed to "We're overloaded… "
    then posted twice!

    weird!

    image MH
  • Rob2Rob2 Member Posts: 2,402
    edited July 2012
    speed=sqrt(linear velocity X^2 + linear velocity Y^2) so accumulate that value once a second and you will get a reasonable approximation of the number of pixels your actor has travelled.
    [GS measures speed in pixels/second]

    If your actor is very lively you will need to sample more often to improve accuracy and adjust your total accordingly. You could say sample every .1s and just divide you total by 10.

    This will only work if velocity is being driven by physics or move/move to/accelerate etc. Interpolate and mouse/touch does not effect velocity.

    edit: you can also use magnitude( linear velocity.X , linear velocity.Y ) to get speed - its basically performing the same calculation and I guess is more straightforward - but seeing the real math is good :)
  • carlblanchetcarlblanchet Member Posts: 755
    @MotherHoose
    The actor moves by being touch and dragged around the scene.
    Thanks for the awesome demo! :) Although it doesn't seem to increase the score (for example by +1 every 5 pixels of distance) when it is dragged around.

    Thanks for the help!
  • carlblanchetcarlblanchet Member Posts: 755
    @Rob2

    Thanks for the detailed explanation! :)
    You say this technique will only work if velocity is being driven by physics or move/move to/accelerate etc, and that Interpolate and mouse/touch does not effect velocity. But does it work with an actor's movement caused by an x and y's constraint attribute of the position to the mouse position?

    Thanks for the help!
  • carlblanchetcarlblanchet Member Posts: 755
    @Rob2 Thanks for all the help! I shall see what I can do with your information. :)
Sign In or Register to comment.