- Home /
Input.GetTouch isn't giving correct position
Hello , I am Moving my game object left and right within X-Y plane same like 2D shooter game. My gameObject get destroyed when it collides.
But collision occures when i write below code:
var amttomove : float = Input.GetAxisRaw("Horizontal") * playerSpeed * Time.deltaTime ;
transform.Translate(Vector3.right * amttomove);
When i move my game object By touch it does not collide.
if (Input.touchCount > 0 &&
Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Translate (touchDeltaPosition.x * playerSpeed * Time.deltaTime, 0 , 0);
}
So what can be the reason? What should i do onTouch so that collision occure ?
Please help me.
Thanks to all of you for your support and help.
Are you moving it faster? It has to be something to do with that as touch has no impact on colliders
playerspeed i have kept only 2.. so its not moving faster. and collider works for my first code. But with touch it doesnot work. :(
Is the object moving similar to the first case when using touch? If that's the case, there should not be any difference in how it collides.
yes that's true but i have also checked position. my enemy pass through my player but don't call onTriggerEnter() .
Same thing and trigger code works for my previous case
Your answer
![](https://koobas.hobune.stream/wayback/20220613095528im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving a GUI Image to the same position as a touch 0 Answers
Drag+an+object+to+touch+position(Problem) 0 Answers
How to get my character to move left to right? 0 Answers
Android double jump not working correctly 1 Answer
Porting to Mobile (Touch Controls) 2 Answers