Rotation and Movement Based on Speed of Tapping
Scone
Member Posts: 26
Hey guys! New user to GameSalad, and pretty new when it comes to game design. I have an issue I've been trying to figure out on my own and through the use of tutorial videos, but just can't get a handle on it. This is essentially what I'm trying to accomplish:
In this game, the player will control a disk (circle) through a series of taps on a touch-screen. What I want to happen is for the speed of rotation AND the rate of acceleration to depend on how fast the player is tapping the screen. As of now, I have my object set to move based on touch, but the furthest I've been able to get from there is an "accelerate towards" movement that has nothing to do with rate of tapping; this is to say nothing of rotation, which I haven't figured out. Any help you can give would be great! Thanks for your time!
In this game, the player will control a disk (circle) through a series of taps on a touch-screen. What I want to happen is for the speed of rotation AND the rate of acceleration to depend on how fast the player is tapping the screen. As of now, I have my object set to move based on touch, but the furthest I've been able to get from there is an "accelerate towards" movement that has nothing to do with rate of tapping; this is to say nothing of rotation, which I haven't figured out. Any help you can give would be great! Thanks for your time!
Comments
And then when the user quits tapping, do you want the spinning to slow down and eventually stop?
Also, you wrote "rate of acceleration", but acceleration is already a rate. (Its the rate at which velocity increases.) Do you mean that you want the velocity to increase at a rate proportional to the speed of tapping? Or do you mean the number of taps (instead of the speed of taps)?
Is the spinning (rotation) tied in somehow to the acceleration? Does the actor move across the scene like a wheel on the road? (The faster it turns, the more distance it covers?) Or is the spinning independent of the the movement across the scene? (Like a spinning top , or a spinning satellite in space?)
A little more detail will help give a more exact answer.
What you are trying to do is very complicated and you will have to do lot of trial and error. It might work for one entity but when you wish to collide it with other actors and add some other feature the coding might not work and have to be refined.
2. And yes, when the user quits tapping, I'd ideally like it to slow down and stop.
3. Sorry for the confusion; I meant to say that the velocity to increase proportionally with speed of tapping. If that's really difficult to do, however, I would be fine with a fixed velocity.
4. Ideally, no, the spinning would not be tied into acceleration. The spinning top analogy is a very good one, in this circumstance.
I can more fully lay out the game, if it helps; the reason I didn't do so now is simply because I'm going piece by piece and the mechanic I'm currently working on is movement.
So the idea would be a series of disks (with different colors and/or patterns) are moving randomly across the screen (or some other object, it doesn't really matter). You control one of these disks that you can move around and cause to spin. The basic idea right now is you gather points by spinning near these other disks. The closer you are and the faster you spin, the more points you earn. Furthermore, if the disk is the same color and/or pattern as yours, that also will earn you more points. This is the most basic layout for the game right now (which I realize sounds silly, but will provide the basis for a more complex project later on).
Aside from the movement and point mechanics as I've described them, I'd also like to implement a collision system. I don't conceive of it being particularly complicated--if I can, I'd like you to knock disks further from you if you're spinning faster, but even just having everything be knocked an equal distance would be fine for a while.
Change Attribute: self.Physics.Angular Drag To: .5
Change Attribute: self.Physics.Drag To: 2
When mouse button is down
--Change Attribute: self.motion.Angular Velocity To: (self.Motion.Angular Velocity +1)*1.3
--Accelerate
----Direction = (??? not enough info to help here)
----Acceleration = self.motion.Angular Velocity
Of course you can mess with all the numbers until it starts to feel right.
EDIT: So what I have so far is I get the character to follow the mouse around using "Move to," but the issue I'm running into is two-fold. One, sometimes when the disk starts spinning, when I tap the mouse again it seems to stop/start over in it's rotation. Furthermore, I'm wondering how I would regulate the rate of rotation (in other words, how quickly the object gets up to max speed).
EDIT 2: Sorry for the quick second edit. I figured out that the speed with which the rotation ramps up is a function of angular drag, but I'm still having some issue with the object occasionally stopping in its rotation. I'm not sure if that's just some graphical error in the testing window or what.
I think the rotational stopping you are seeing is actually analogous to the optical illusion you see when something is rotating so fast that it looks like it starts to stand still and then go backwards.
You cannot (as far as I know) use max speed to limit angular rotation. Max speed is for linear velocity. If you want to limit angular rotation to a certain 'speed' then you can use a min() function. So in the example above you can get rid of the 'rotating so fast it seems to stop' bug by modifying the formula to something like the following:
Change Attribute: self.motion.Angular Velocity To: min(1000,(self.Motion.Angular Velocity +1)*1.3)
The min() function tells GameSalad to choose the smaller value of the two. So the actor's rotation will never get above 1000. Its really handy for things like this.
EDIT: There was actually one other question I forgot about. When setting up that equation you gave above, I had to set up two movement equations. One "accelerate towards" in which acceleration was specified as "self.motion.angularVelocity" and one ,"move to" for the disk movement. Am I correct in thinking I needed two? Based on what I saw, the first accelerate towards equation had to do with disk spinning and not the movement around the scene, and so needed a second equation.
You don't need two movement behaviors. The 'accelerate towards' behavior was just using the angular velocity as a speed -- so that the actor's acceleration towards a spot was a function of the speed of rotation. (Kind of a 'the faster it spins, the faster it moves' kind of relationship.) But its not necessary. If you have a 'move to' behavior that is working for you then that's great.
And for the first question:
There is a magnitude function that gives you the distance between two actors. You could make a system that detects the distance between each actor and the disk. Then you can use that distance in a formula to give points. Maybe you could use something like ((distance*angular velocity)/numOfActorsOnScene) or whatever.
I'll have to to play around with those movement behaviors again; the reason I put in a "move-to" was partly because the object moved extremely slowly no matter how fast I tapped, but that might have simply been because the multiplicative amount in the change attribute rule (referring to: Change Attribute: self.motion.Angular Velocity To: (self.Motion.Angular Velocity +1)*1.3) was too small. I increased it later, but only after I added the "move-to."
As to the point system, I'll play around with it today, and perhaps that will give me some more useful feedback to provide. Thank you for your time!
As long as you are playing around with movement behaviors -- I'd suggest investigating the 'interpolate' behavior. If you use its "ease in / ease out" function you can achieve some nicely organic movement behaviors.
Constrain Attribute: mydistance To: magnitude(game.Mouse.Position.X-self.Position.X, game.Mouse.Position.Y-self.Position.Y)
You can test to see if the distance is small enough and then use the rotation of the actor to determine points:
When myDistance < 100
--Constrain Attribute: myPoints To: floor(self.Rotation/360)*10
EDIT: Is this something you can also change depending on the different actors? So being near one actor gives more points than being near another.
EDIT: I think I figured it out. I added two new attributes to the game window (player's x and player's y) and set it up for them to be constrained to self.position.x and y. From there I am building the rest of the functions.
Glad you are getting things figured out!
EDIT 3: Another issue is that if the player object gets knocked in such a way that it spins in the opposite direction for a bit, the score drops down. Is there a way to prevent that drop from happening (even if it means that the object can spin in only one direction)?
EDIT: I fixed this problem, and thought I'd write it out in case someone else has had the same issue. Basically, I changed from a default size (I think it was set to iPhone) to the iPad 1024x768. What messed up the game, though, was that I changed the sizes of screens but not the game! Once I went into game attributes and set that to the correct size, my movement was fixed.
Some great info here, thanks for posting !
When myDistance < 100
-- Change Attribute self.oldRotation To: self.Rotation
-- When self.Rotation < self.oldRotation -360
---- Change Attribute myPoints To: myPoints + 10
---- Change Attribute self.oldRotation To: self.Rotation
Note1: oldRotation is an attribute that you create
Note2: The above behaviors are for an actor rotating clockwise. They would need to be reversed for an actor going counterclockwise.