Controlling Acceleration Speeds.. *Help* Please :)
chosenonestudios
Member Posts: 1,714
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!
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
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.
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.
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