I’m tying to make an object jump but still have the object move based on the x axis of the players touch. The result I got was that the object glitches to one point on the y axis and ignore the jump trigger when I use touch but I am still able to control the x movement.
public class Jump : MonoBehaviour
{
public Rigidbody rb;
public GameObject gizmo;
public Vector3 touchPosition;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
Touch touch = Input.GetTouch(0);// * Time.deltaTime * speed
float gizmoy = gizmo.transform.position.y;
touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, transform.position.y, 3));
transform.position = touchPosition;
}
void OnTriggerEnter(Collider other)
{
rb.AddForce(new Vector3(0, 10, 0), ForceMode.Impulse);
}
}