Quote: "I love this quote, I'll use it on the AppGameKit website "
Ima gon be famous!
Quote: "Looks very smooth and polished.
Nice work !"
Thanks!
---
So I had a lot of complaints about people having difficulties trying to aim precisely, especially when bouncing off a corner or something. The reason for this was if you move your finger 1 pixel, it could be the difference between landing on one side of the level or the other. I had a few idea about how to fix this, such as adding a confirmation button to fire alongside a slider to finely adjust your aiming. Unfortunately this wouldn't work in many of the later levels since they require your to aim and shoot while moving or extremely rapidly.
Fortunately I came up with a solution, here's how I did it:
I realised that it's possible to detect if the player is struggling to aim precisely. They will be moving their finger slowly, the BioUnit will be almost still, and most importantly, the final position of the BioUnit will vary wildly between frames. So I simply store the final BioUnit position from the previous frame and if it's changed by more than 5 pixels in either axis (and if they other two conditions are met), the aiming mechanism will be put on fine mode. Here's my code:
[Givng away all my trade secrets here
]
Touch control code:
if GetPointerPressed()
for k=1 to 10
nx[k]=ScreenToWorldX(GetPointerX())
ny[k]=ScreenToWorldY(GetPointerY())
next
endif
nx[10]=nx[10]+((ScreenToWorldX(GetPointerX())-prevx)*fineness) //prevx is the x position from the previous frame
ny[10]=ny[10]+((ScreenToWorldY(GetPointerY())-prevy)*fineness)
for k=1 to 9
nx[k]=nx[k+1]
ny[k]=ny[k+1]
next
[As you can see, the touch coordinates are stored in an array which is 'bumped' back each frame (meaning that nx[10] stores the current x coor, and nx[1] stores the x coor from 10 frames ago. The reason I do this is when you release, people always wobble their finger a bit. I use nx[1] for the preview, but nx[7] to actually fire. This makes sure their shot is steady]
Fineness detection code:
if k=50
if lastplayerfinalposx-GetSpriteX(player.id)>2 or lastplayerfinalposy-GetSpriteY(player.id)>2 //detect if the final player position is varying wildly
if abs(ScreenToWorldX(GetPointerX())-prevx)<1.5 and abs(ScreenToWorldY(GetPointerY())-prevy)<1.5 //only if the touch coordinates aren't moving super fast
if abs(player.vel.x)<1.5 and abs(player.vel.y)<1.5 //only if the player isn't moving super fast
fineness=0.1
endif
endif
else
//I forget why I put this line in but I'm afraid to remove it
//POST EDIT I remember now. So if the final position ISN'T varying AT ALL, then leave the fineness where it is. This allows the player to move their finger super slowly and maintain fineness
if lastplayerfinalposx-GetSpriteX(player.id)<>0 and lastplayerfinalposy-GetSpriteY(player.id)<>0
if fineness<1 then fineness=fineness+0.1
endif
endif
lastplayerfinalposx=GetSpriteX(player.id)
lastplayerfinalposy=GetSpriteY(player.id)
endif
This code is executed in a for k=1 to 50 loop which is stepping the physics sim each frame to trace the player position while aiming. So it's detecting to see if the final position (hence
if k=50) has changed a lot since the previous frame and if so, adjusts the fineness variable which in turn makes their aiming finer in the first code block. It's also checking to make sure the BioUnit isn't moving too fast and the player isn't swiping their finger super fast either.
These few lines of code are a massive quality of life improvement to the gameplay. This is why I love coding, solving these sorts of problems
EDIT: Of course I pushed out the update with hardly any testing whatsoever and realised several critical mistakes in my code
after the update
Fixed them now though