Hello,
I am working on a game where objects fall from the top of the screen. I have them working with raycasting. The game is 2D. The issue I am having is if they are going too fast, even if you tap on them, they do not ALWAYS get detected by the raycast. How can I keep up with the speed of a falling object? I have tried boxcast & circlecast but they seem to only work if you tap far ahead of the falling object. I have adjusted mass, drag & gravity scale. It seems if I do anything faster than 10 gravity scale the raycast is very hard to keep up with the touch positions.
Here is some of my code just to make it more understanding.
if (Input.touchCount > 0) {
if (Input.touchCount == 1) {
Touch currTouch = Input.GetTouch(0);
if (currTouch.phase != TouchPhase.Began || currTouch.phase != TouchPhase.Ended)
{
return;
}
CheckForSplat(currTouch.position);
}
else {
for (int i = 0; i < Input.touchCount; i++) {
Touch currTouch = Input.GetTouch(i);
if (currTouch.phase != TouchPhase.Began || currTouch.phase != TouchPhase.Ended)
{
return;
}
CheckForSplat(currTouch.position);
}
}
}
void CheckForSplat(Vector3 pos) {
RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero);
}
randomVelocity = Random.Range(-200.0f, -300.0f);
newDroplet.GetComponent().SetParent(mainCanv.transform);
newDroplet.transform.SetAsLastSibling();
newDroplet.transform.localScale = new Vector3 (1.0f, 1.0f, 1.0f);
newDroplet.rigidbody2D.mass = 0.25f;
newDroplet.rigidbody2D.drag = 0.0f;
newDroplet.rigidbody2D.gravityScale = 10.0f;
newDroplet.rigidbody2D.isKinematic = false;
newDroplet.rigidbody2D.velocity = new Vector2(0, randomVelocity);
newDroplet.rigidbody2D.AddForce(spawnerPosition.forward, ForceMode2D.Impulse);
↧