Hi everyone, I’m making a game for a university project. I have this gun, that impulse objects or platforms as telekinesis would do, like star wars force. The thing is, I can’t manage to impulse objects in the desired direction. I’m trying to impulse where the camera is aiming, the normal of the raycast I think we could say, but it won’t work. Tried many things, but the objects are impulsed to either wrong directions or just straight forward.
This is my actual code:
private void Update()
{
if (Input.GetMouseButtonDown(0)) {
animator.SetTrigger(“IsShooting”);
shot.Play();
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.CompareTag(“Kinetic”))
{
Vector3 direccion = (hit.point - transform.position).normalized;
Quaternion rotacion = Quaternion.LookRotation(direccion);
Vector3 rotacionVector = rotacion.eulerAngles.normalized;
Rigidbody rb = hit.collider.GetComponent();
if (rb != null)
{
rb.AddForce(rotacionVector * fuerzaTelekinetica, ForceMode.Impulse);
}
}
}
}
}