Making an effective flicking mechanic in GS that feels natural for the player
HoneyTribeStudios
Member Posts: 1,792
This is something I've spent a long time getting right for my new game that's coming out soon, Yam Yam. So you flick berries across the screen. With any game, the controls will make or break the gameplay so here is what I've ended up with which works well and feels natural to the player.
I have lots of conditions in the rules that are my specific to my game. I won't bother writing those but just give you the overview.
Attributes needed - they can be self or game attributes. But assuming different actors will be referencing these attributes game attributes will be easier to work with.
game.startTime (real - 0)
game.endTime (real - 0)
game.startX (integer - 0)
game.startY (integer - 0)
game.endX (integer - 0)
game.endY (integer - 0)
game.P (real - 0.33)
game.M (real - 1.0)
game.flickTime (real - 0)
game.flickDistance (integer - 0)
game.flickAngle (angle - 0)
When mouse button is down
change game.startTime to game.time
change game.startX to device.touch.X
change game.startY to device.touch.Y
When mouse button is up
change game.endTime to game.time
change game.endX to device.touch.X
change game.endY to device.touch.Y
change game.flickTime to game.M *pow((game.endTime - game.startTime),game.P)
To explain the above: we are cube rooting the time. Or making it to the power game.P (0.33) which is the same thing as cube rooting it. But you can adjust the 0.33 to suit the feel of your game.
And then we are multiplying the time by game.M.
Start with 1.0 and then adjust to suit your game.
I also have an 'easy flick' gameplay mode where game.M is changed to 0.3. This means that young children will still be able to do powerful flicks even if they can't physically flick that fast.
So now we have established the time. Next is the distance and angle. We can use the magnitude and vectorToAngle functions in GS (instead of manually typing in the trigonometry)
Change game.flickDistance to magnitude(game.startX - game.endX, game.startY - game.endY)
Change game.flickAngle to vectorToAngle(game.endX - game.startX, game.endY - game.startY)
So now we can use these values in your ammo, or what ever it is you are flicking across the screen.
So in your ammo object use a change velocity behavior.
In the speed put game.flickDistance/game.flickTime
I also use the min and max functions to have a minimum and maximum velocity that makes sense to the gameplay. So no dribble shots and no sonic boom shots!
For the angle put game.flickAngle.
And have them as 'relative to scene'
So that's it. As there are no constrains this method is easy on the device processor so doesn't really effect frame rate.
I have lots of conditions in the rules that are my specific to my game. I won't bother writing those but just give you the overview.
Attributes needed - they can be self or game attributes. But assuming different actors will be referencing these attributes game attributes will be easier to work with.
game.startTime (real - 0)
game.endTime (real - 0)
game.startX (integer - 0)
game.startY (integer - 0)
game.endX (integer - 0)
game.endY (integer - 0)
game.P (real - 0.33)
game.M (real - 1.0)
game.flickTime (real - 0)
game.flickDistance (integer - 0)
game.flickAngle (angle - 0)
When mouse button is down
change game.startTime to game.time
change game.startX to device.touch.X
change game.startY to device.touch.Y
When mouse button is up
change game.endTime to game.time
change game.endX to device.touch.X
change game.endY to device.touch.Y
change game.flickTime to game.M *pow((game.endTime - game.startTime),game.P)
To explain the above: we are cube rooting the time. Or making it to the power game.P (0.33) which is the same thing as cube rooting it. But you can adjust the 0.33 to suit the feel of your game.
And then we are multiplying the time by game.M.
Start with 1.0 and then adjust to suit your game.
I also have an 'easy flick' gameplay mode where game.M is changed to 0.3. This means that young children will still be able to do powerful flicks even if they can't physically flick that fast.
So now we have established the time. Next is the distance and angle. We can use the magnitude and vectorToAngle functions in GS (instead of manually typing in the trigonometry)
Change game.flickDistance to magnitude(game.startX - game.endX, game.startY - game.endY)
Change game.flickAngle to vectorToAngle(game.endX - game.startX, game.endY - game.startY)
So now we can use these values in your ammo, or what ever it is you are flicking across the screen.
So in your ammo object use a change velocity behavior.
In the speed put game.flickDistance/game.flickTime
I also use the min and max functions to have a minimum and maximum velocity that makes sense to the gameplay. So no dribble shots and no sonic boom shots!
For the angle put game.flickAngle.
And have them as 'relative to scene'
So that's it. As there are no constrains this method is easy on the device processor so doesn't really effect frame rate.
Comments
- Thomas
@SnapFireStudios - Maybe... I'll have to strip out everything except the flick rules first. Which could take a while. This game started out last May so it's quite 'busy' in terms of actors and rules now.