I've been searching around but can't seem to find the answer of my question. I'm very new to Unity so please take everything with a bit of salt and explain simple if you have a solution, thanks in advance!
![alt text][1]
[1]: /storage/temp/67376-ballexp.png
Trying to show what i want to accomplish with this picture i've made above, I want the object to follow the cursor but still stay on the ground-surface. Most of the things i've found the Object moves to the cursor (The ball starts flying and gets the exactly same position as the cursor and ignores everything else). I just want it to "move with" the cursor in X-axis and not in Y-axis ==> Always stay on the platform.
using UnityEngine;
using System.Collections;
public class FollowMouse : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
float dist = transform.position.z - Camera.main.transform.position.z;
Vector3 pos = Input.mousePosition;
pos.z = dist;
pos = Camera.main.ScreenToWorldPoint(pos);
pos.y = transform.position.y;
transform.position = pos;
}
}
UPDATE : Seems like i kinda fixed it myself, It's not that smooth thought, it's moving SUPER fast wich i don't want and colliding pretty weird (I have it constantly bouncing)
↧