Rotation and Movement Based on Speed of Tapping

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!

Comments

  • famekraftsfamekrafts Member, BASIC Posts: 834
    When the player touches the character make Boolean true. If it is true every time it taps make another attribute say tapping to tapping + 1. Now if tapping is 1 make rotation speed to 10, 2 then 20 and so on.
  • SconeScone Member Posts: 26
    So Boolean is changed with a "changed attribute" rule, correct? Do I need to then have some sort of function whereby the Boolean sets itself to false? If I'm totally off, or it sounds like I don't understand, I apologize; I'm only generally aware of how the Boolean functions.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Can you clarify a bit more of what you want? For example, do you want the actor to spin faster and faster according to how fast the user taps? Or do you mean the number of taps (instead of the speed of taps)?

    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.
  • famekraftsfamekrafts Member, BASIC Posts: 834
    You have to put it off say if person doesn't tap for more than 2 seconds. So you need to have true false attribute, tapping number attribute and a timer. You off it and make the tapping back to zero in the otherwise of the rule.

    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.
  • SconeScone Member Posts: 26
    edited November 2012
    Can you clarify a bit more of what you want? For example, do you want the actor to spin faster and faster according to how fast the user taps? Or do you mean the number of taps (instead of the speed of taps)?

    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.
    1. I want the actor to spin faster and faster according to how fast the user taps (up to some maximum speed, I suppose).
    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    OK -- try this on an actor:

    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.
  • SconeScone Member Posts: 26
    Thank you, I will try this! With direction, would it help to say that I intend for the disk to move to where you tap the screen. By this, I don't mean it instantly teleports to the spot, but moves across the screen to the spot.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    OK -- you have several different options to get the disc to go to the touch point. Among others, you can use "Accelerate Toward" or "Move To" or "Interpolate" behaviors. As probably expected, each behavior gives a slightly different feel to the movement toward the touch point.
  • SconeScone Member Posts: 26
    Alrighty; I'll give those a shot and let you know how it goes. Thank you so much for your help!
  • SconeScone Member Posts: 26
    edited November 2012
    OK -- try this on an actor:

    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.
    So when you say Acceleration = self.motion.Angular Velocity, I'm a little confused as to where that goes. My initial reaction was to use that for "with acceleration..." under "Accelerate towards," but I'm not sure. I was also a bit confused as to where to put direction. By that do you mean, "Accelerate towards the point"?

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited November 2012
    Angular drag is the rate at which the rotation slows down. It is a kind of rotational friction. (So if you set angular drag higher, the actor will stop rotating quicker.)

    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.
  • SconeScone Member Posts: 26
    edited November 2012
    Fantastic; thanks so much for the help! Now, since we're on the subject of rotation and movement, is it possible to set up a point system dependent on proximity and the speed of rotation? So the general idea is there are other objects randomly moving in the environment, and you try to spin next to them without knocking them around. You get more points over time the closer you are to the other objects within a certain region, and also the faster you're spinning (the points would be given, say, every half second or something).

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Um... second question first:
    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.
  • SconeScone Member Posts: 26
    Sorry for that awkward arranging of questions!

    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!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Glad you are enjoying experimenting with GameSalad.

    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.
  • SconeScone Member Posts: 26
    So with this point system, can you make it give you a certain amount of points with each rotation? What I'd ideally like to have is that once you reach a certain distance (let's say 3 units), every time your disk does a full rotation you get a number of points (let's say 10).
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    You can find the distance between two things with the magnitude function. For example the distance between an actor and the mouse can be determined by:

    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
  • SconeScone Member Posts: 26
    edited November 2012
    Absolutely fantastic; to be able to do even that much is more than I had hoped. I will get on this ASAP!

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Yes, you can create several attributes that would correlate with the other actors' distances. Perhaps you could create actor1Distance, actor2Distance, etc. Then you would have several distance calculations to make -- one for each actor. (And several 'point givers' -- one for each actor's distance from the main spinner.)
  • SconeScone Member Posts: 26
    edited December 2012
    Is myDistance an attribute already in the game, or is this one I'd have to make. If it is one you need to create, am I correct in assuming this would need to be an integer attribute?

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Yes -- in the examples I gave above, 'myDistance' was an attribute that you would make. It can be either an integer or a real -- depending on if you need whole numbers or if you need numbers down to the decimals. (I tend to use real numbers because I worry about rounding errors that might occur over many iterations. But I don't know if that is a legitimate concern or not.)

    Glad you are getting things figured out!
  • SconeScone Member Posts: 26
    edited December 2012
    EDIT 2: The issue I'm running into now has to do with displaying the scores. So what is essentially happening is that, instead of the points only accounting for the number of spins while within that minimum distance we set, it will also add points for the spins NOT within that range. For example, I have it set to 10 pts per full spin. If I were to go into a corner away from the NPC and spin 10 times, the next time I come within that minimum distance the game adds in 100 points. I only want it to add points for the spins WHILE IN that minimum distance.

    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)?
  • SconeScone Member Posts: 26
    edited December 2012
    A new, major problem has arisen with my game. Today I changed the size of the play screen and added the follow camera rule to the main actor. Furthermore, I also put in some new menu scenes (though currently they are disabled). What seems to be happening now is that my main actor no longer follows the direction of the mouse click. When I start clicking, it always just moves into the bottom left corner; it may eventually move up, but it keeps then starting to move back down, and never really follow my mouse 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.
  • SocksSocks London, UK.Member Posts: 12,822
    @RThurman

    Some great info here, thanks for posting !
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited December 2012
    EDIT 2: The issue I'm running into now has to do with displaying the scores. So what is essentially happening is that, instead of the points only accounting for the number of spins while within that minimum distance we set, it will also add points for the spins NOT within that range. For example, I have it set to 10 pts per full spin. If I were to go into a corner away from the NPC and spin 10 times, the next time I come within that minimum distance the game adds in 100 points. I only want it to add points for the spins WHILE IN that minimum distance
    I think I see what you want, try this instead:

    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.
Sign In or Register to comment.