Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Player follows mouse, but I need only Y

$
0
0
Hi everyone! as you can read in the title I have this script that follows the mouse in X and Y axis, but I only want it to move in Y axis. I'm a total noob so I have no idea how to do it, here's my script: using System; using UnityEngine; public class PlayerControl : MonoBehaviour { private Vector3 _target; public Camera Camera; public bool FollowMouse; public bool ShipAccelerates; public float ShipSpeed = 2.0f; public void OnEnable() { if (Camera == null) { throw new InvalidOperationException("Camera not set"); } } public void Update() { if (FollowMouse || Input.GetMouseButton(0)) { _target = Camera.ScreenToWorldPoint(Input.mousePosition); _target.z = 0; } var delta = ShipSpeed*Time.deltaTime; if (ShipAccelerates) { delta *= Vector3.Distance(transform.position, _target); } transform.position = Vector3.MoveTowards(transform.position, _target, delta); } } I'm trying to create a control like [THIS GAME][1] you can see gameplay at 0:40, you touch the screen and the spaceship follows the touch in Y axis if you know a tutorial or something. Thank you! [1]: https://vimeo.com/102765484

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>