Controlling Acceleration Speeds.. *Help* Please :)

chosenonestudioschosenonestudios Member Posts: 1,714
edited November -1 in Working with GS (Mac)
I would like an actor when it collides with the main actor to move a speed according to how fast it was hit by the main actor....

I was planning on like constraining the speed to both actors and going that route....

But apparently you can't do that because the main actor is being moved around by your finger... so it technically doesn't have a velocity....

Any suggestion on how I should go about doing this?

Your help is appreciated Thank You! :)

Comments

  • rebumprebump Member Posts: 1,058
    Yeah, constrains that update an actor's position yield no velocity values for that actor.

    You could try and produce your own inside a fine granularity timer (like "Every 0.02 or such"). At the start of the timer, save the actor's X and Y position to attributes (call them "OldX" and "OldY" or something). Then, change another attribute (call it "myVelocity" or something), to the value `"magnitude(self.Position.X - oldX, self.PositionY.Y - oldY)"`. If you wanted them broken out, you could even just compute the difference in current X and old X for horizontal velocity and do the same with Y for vertical velocity. May need to add a nested "after 0.01" timer that contains the magnitude calculation. ADDED: I would then compare the values you generate with values on another actor that is moving/displaying it's values. You could move your actor (via touch) alongside that actor that is moving on its own displaying values for each. This would give you a bit of data to see if you need to scale your computed value a bit to get them to mate up better with the system's values.

    In the actors being hit by the touch controller (main) actor, you could inspect the computed velocity and use a percentage of it for its own velocity/accelerate behavior.

    Something along those lines.

    You could use "vectorToAngle()" with the values above to determine the general direction/heading the touch controlled actor is moving too.
  • chosenonestudioschosenonestudios Member Posts: 1,714
    thanks rebump! I appreciate it, I'll go see what I can do!
  • rebumprebump Member Posts: 1,058
    It's worth a shot. Won't be the most accurate but you should be able to generate some values to compute a value for use in the deflecting actors.

    I noted the "vectorToAngle()" method here for heading/direction:

    http://gamesalad.com/forums/topic.php?id=6982#post-45926

    but the "magnitude()" method for velocity is similar.

    Keep in mind, any "magnitude()" values for velocity need to take into account the time from when the oldX/oldY were sampled to when they are used in the "magnitude()" computation. In my example above, with the outer timer at "every 0.02 seconds" and the inner timer "after 0.01 seconds", you time would be 1/100th a second. So if your magnitude was say 3.2 (pixels) per 1/100th a second, multiply that by 100 to get 320 pixels per second (and hopefully that corresponds somewhat with what a system velocity of 320 represents).

    If you slow down the timer interval, things could get choppier.
  • chosenonestudioschosenonestudios Member Posts: 1,714
    Hey, I used the vector to angle and that worked great, still having problems with the speed though, any suggestions?
  • rebumprebump Member Posts: 1,058
    If you got the "vectorToAngle()" (using OldX/OldY) working, the magnitude stuff should be very similar...be sure to read my post (in this thread) above this one regarding sampling time (it is in the large, second-to-last paragraph).
  • chosenonestudioschosenonestudios Member Posts: 1,714
    k I'll double check
  • chosenonestudioschosenonestudios Member Posts: 1,714
    oops, I thought it was working, but apparently not.... there was still a collide behavior there :(
  • wayneh001wayneh001 Member Posts: 300
    @ChosenOneStudios:
    I've uploaded a Hockey Template game which demonstrates 2 player multi-touch with constrained zones. If you implement the 'velocity' attribute described within this post you can get a pretty good simulation of hitting the [puck] harder/softer.

    http://gamesalad.com/game/play/60145

    Wayne
  • chosenonestudioschosenonestudios Member Posts: 1,714
    ty very much wayne! I'll check it out!
Sign In or Register to comment.