hi guys, i’m a beginner to unity technology and this is my first question in this forum.
i have a little problem, the problem is i can’t shoot my prefab to the touch position, i googled around a lot…but nothing useful even that with my current code i can shoot to the position of touch but i can’t shoot to left or right its just stuck its only goes forward
this is my code i attached to my main camera in the scene
using UnityEngine;
public class TouchManager : MonoBehaviour
{
public Rigidbody projectFile;
public Transform firePosStart; //empty game object to get the start posX,Y,Z
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
Touch myTouch = Input.GetTouch(0);
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
Rigidbody clone;
projectFile.transform.LookAt(new Vector3(myTouch.position.x, myTouch.position.y));
clone = Instantiate(projectFile, firePosStart.transform.position, firePosStart.transform.rotation) as Rigidbody;
clone.AddForce(projectFile.transform.forward * 2000);
}
}
}
and this a the result as u can see the fireball is moving forward no matter where i click what’re is that even if i click left or right the fireball keep moving forward and this is not what i want, i want the fireball to go to the touch position
please not that i don’t care to my script u can change it as u like
feel free to make the fireball shoot to thetouch position as u like ![]()
please if anyone have any thoughts please share it with me cause this is start become annoying and thanks anyway ![]()
