- Home /
Unity Android movement
Hi. I learn Android scripts. I have to create this movement:
When I hold finger on screen, my hero goes his way.
I don't have any idea, so maybe you help me? I begin in Android.
Thanks;)
Your question is very very very broad. What have you tried? What are you stuck on? What is your background? Right now it sounds like you want someone to just write a bunch of code for you, and unfortunately, that's not how Unity Answers works.
I'am from $$anonymous$$nd, so I don't understand English well. I question who help me, maybe who have this script and share on this question.
Yes, of course, I have a simple move at the moment but this more suits me;)
Answer by RyanZimmerman87 · Jul 27, 2013 at 10:15 AM
I currently have an Android project where you tap the screen to control where the player goes. You could easily change it to be holding down your finger by changing:
if (Input.GetButtonDown ("Fire1"))
to:
if (Input.GetButton ("Fire1"))
So without the details of what kind of camera view you have it's a bit hard to answer properly. But essentially you can shoot a ray from the camera's point of view. Where this ray hits the ground or any objects you interact with is where the player will move.
I can't offer much beyond that simple advice despite being quite far in my games development. I wasn't able to find any tutorials for setting up a game with these kind of controls so everything I did was just trial and error and freestyle programming.
But essentially you cast rays to determine where to go, then you must do ridiculous things to get it to work correctly and look good for your specific project, so I can't go into those details haha.
I can give you the starting point though:
if (Input.GetButton ("Fire1"))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit rayHit;
if (Physics.Raycast(ray, out rayHit, 150)
{
rayVector = rayHit.point;
playerDestinationVector = new Vector3 (rayVector.x, this.playerTransform.position.y, rayVector.z);
rayHitObject = rayHit.collider.gameObject;
stringRayName = rayHitObject.name;
}
That gives you the basic things you need to work with.
And after that let the madness begin...
It works but if you aren't at least twice as smart as me it won't be easy haha. This kind of system requires excessive amount of control structure compared to a PC game using (WASD) controls.
Here's a screenshot of the current project I'm using this kind of system with so you can have a better idea if it might work for what you are trying to do: