i modified the follow script to attach objects to my grapling hook, when it collides with them, but i can’t figure out how to properly release them when i press right click. i am trying to change the target to my nohand gameobject’s transform, but it only works if i have not yet hit any other object.
anyone of you see a fix for it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grab : MonoBehaviour
{
private Animator anim;
public Vector3 offset = new Vector3(0f, 0f, 3f);
public Transform target;
public Transform nohand;
//nohand is a empty gameobject
public Transform glove;
public int distance = 3;
void Start()
{
Vector3 playerPos = glove.transform.position;
Vector3 playerDirection = glove.transform.forward;
Quaternion playerRotation = glove.transform.rotation;
anim = GetComponent<Animator>();
}
void OnCollisionEnter(Collision FindTarget)
{
if (FindTarget.gameObject.tag == "Enemy" || FindTarget.gameObject.tag == "Rabbit")
{
target = FindTarget.transform;
}
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
anim.SetTrigger("grab");
}
if (target != null)
{
target.transform.position = glove.transform.position + offset;
target.transform.forward = glove.transform.forward + offset;
target.transform.rotation = glove.transform.rotation;
}
else if (Input.GetMouseButtonDown(1))
{
target = nohand;
}
}
}
btw. thanks you to alexander for helping me with the sound earlier in case you read this