- Home /
Tap n move style script not keeping player grounded
Hey everybody,
This might be something super obvious, but I think I just need another set of eyes on it. I'm making a game that's kind of loosely like slither.io (control wise), but with spheres rather than snakes that bump in to one another trying to force enemies off of a platform. It's being built for iOS, and my player is supposed to be in a constant state of motion and changing direction based on where the user taps the screen. That much is working but my player is also sort of bouncing and floating up towards the screen. I'd lock the Y position, but we need to be able to fall off the platform.
Admittedly this project fell into my lap a bit when I offered to do design work, and now I'm the sole developer - and not fantastic on the development side.
Huge thanks in advance.
Here's my working script.
using UnityEngine;
using System.Collections;
public class TapNMove : MonoBehaviour {
public float speed = 12;
public float maxHeight = 1;
public Vector3 pointInWorld;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position += transform.forward * Time.deltaTime * speed;
if (Input.touchCount > 0) {
// The screen has been touched so store the touch
Touch touch = Input.GetTouch (0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
// If the finger is on the screen, move the object smoothly to the touch position
Vector3 touchPosition = Camera.main.ScreenToWorldPoint (new Vector3 (touch.position.x, touch.position.y, 10));
transform.LookAt (touchPosition);
}
//if (transform.position.y > maxHeight) {
// transform.position.y = maxHeight;
//}
}
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
iPhone profiler evaluation 1 Answer
Player2d Movement (rigidbody2d.velocity) with small vibrations, very similar to small collisions 1 Answer
Serialization of Dictionary> in Unity 4,6 0 Answers
Using AssetBundles as IAP Crashing 0 Answers