- Home /
Adding two different forces on same gameobject
Hi! My player game object continuously moving in forward direction with constant velocity after colliding with the platform. I want my player to move left and right along an axis. the problem is when I touch my player (On android), player left & right movement working fine but its velocity in forward direction reduces to zero.
My code for left and right movement.
// Update is called once per frame void Update() { float speed = 0.1f; if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { // Get movement of the finger since last frame Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; // Move object across XY plane transform.Translate(touchDeltaPosition.x * speed * Time.deltaTime, 0, 0); } }
Answer by Aaqib_Zafar · Nov 07, 2018 at 05:45 AM
transform.Translate(touchDeltaPosition.x speed Time.deltaTime, 0, 0);
the problem is in above line, since there are three axis in vector passed to the translate function
here you are giving some values to for the X (touchDeltaPosition.x speed Time.deltaTime) but for the Y and Z you passing zero which is causing your object to stop, so pass some value speed value greater than zero in z value also, lets say, transform.Translate(touchDeltaPosition.x speed Time.deltaTime, 0, 5*time.deltatime);
Ok. Player already has velocity in Z direction. If I pass some value there then it will interfere with its existing velocity which I don't want.
Your answer
![](https://koobas.hobune.stream/wayback/20220612181632im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem in multi touch 0 Answers
Count Number of Touches made in Android 2 Answers
move object x axis with finger touch 0 Answers
Touch controls for Pong based video games for Android 0 Answers
3d car left and right touch input 2 Answers