- Home /
Character keeps snapping between two finger positions [Mobile, Android, Raycast]
Hello everyone,
I'm currently working on an Android title, and am having an issue with Input. I guess I'd still be considered a beginner with javascript, but I've got a good idea on how it works.
I currently have it so my left thumb controls the characters position by dragging, and my right thumb is in charge of shooting and power-ups. Now here's my issue:
We've got the character controllable, and the attack button working 100%.
When we are holding the attack button down, the player starts shooting properly. But...
When the player moves within range of the attack button, it snaps to its position, and cant move the character anymore unless we let go of the attack button, and are able to gain control back.
We've narrowed it down to this:
The characters hit box for the raycast detection is large. Reason for that is so when players are moving their thumb around quickly, they wont loose control of the character because of screen response delay. With that in mind, the character is snapping to the other thumb detection (the attack button thumb), because the raycast is detecting all finger inputs on screen, and when the other thumb is in range of the hit box, it snaps to it.
I've been trying to figure out how to solve this, and I think I have the solution in my head. I'm just having a hard time putting it into code...
I was wondering if its possible to only allow the raycast to detect one finger. So once the player gains control of the character, no other finger Inputs will interrupt the control.
I've attached the player control code below. Any help will be greatly appreciated.
var player;
player = GameObject.Find("PlayerFingerZone");
private var ray : Ray;
private var rayCastHit : RaycastHit;
function Update ()
{
for (var touch : Touch in Input.touches)
{
ray = Camera.main.ScreenPointToRay (touch.position);
if(Physics.Raycast ( ray, rayCastHit))
{
transform.position.x = rayCastHit.point.x;
transform.position.z = rayCastHit.point.z;
}
}
}
Thanks in advance.