- Home /
Question by
imM4TT · Apr 01, 2018 at 05:02 PM ·
androidrigidbodytouch controls
Android increase force of object by position of touch
Hello, I would like to increase the force of the rigid body with the position of the touch.
More the touch is far away of the middle of the screen, more the force added should be high
I actually have this script :
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
if (touchDeltaPosition.x > 0)
{
Rb.AddForce(Vector3.right * speed * Time.deltaTime );
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Rb.AddForce(Vector3.right * speed * Time.deltaTime );
}
}
if (touchDeltaPosition.x < 0)
{
Rb.AddForce(-Vector3.right * speed * Time.deltaTime );
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Rb.AddForce(-Vector3.right * speed * Time.deltaTime);
}
}
if (touchDeltaPosition.y > 0)
{
Rb.AddForce(Vector3.forward * speed * Time.deltaTime );
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Rb.AddForce(Vector3.forward * speed * Time.deltaTime);
}
}
if (touchDeltaPosition.y < 0)
{
Rb.AddForce(-Vector3.forward * speed * Time.deltaTime );
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
Rb.AddForce(-Vector3.forward * speed * Time.deltaTime );
}
}
}
Any idea ?
Comment
Your answer
Follow this Question
Related Questions
Object is moving slower on other device (Android) 1 Answer
Differentiate swipe from tap android 0 Answers
Move rigid body using explosion force in C# 0 Answers
Touch Control for 2D Game 0 Answers