Hey there,
I am trying to make a hook since a loooooong while. Now I am nearly done, but the player isn’t moving. So I tried to use my script on another object (a simple sphere) and it worked…
The next thing I did, was disabling all scripts of my player (not the hook script), but the player still didn’t move.
My hook-scipts: On the player I have got a really simple script, which shoots a sphere as a hook. On the hook itself I have got a script that stops the hook if it’s touching something and then move the player to the position of the hook.
Scipt on the hook:
using UnityEngine;
using System.Collections;
public class OnHook : MonoBehaviour {
public GameObject player;
public GameObject hook;
GameObject other;
public float speed = 20;
public bool grabbed = false;
// Use this for initialization
void Start () {
other = GameObject.FindWithTag ("Enemy");
}
// Update is called once per frame
void Update () {
if(grabbed)
{
// other.rigidbody.AddForce((transform.position - other.transform.position).normalized * speed); // This was my try using addForce
player.transform.position = Vector3.Lerp(player.transform.position, hook.transform.position, Time.deltaTime * speed);
}
}
void OnTriggerEnter(Collider col){
if(col.tag != "Player" && col.tag != "Hook")
{
grabbed = true;
rigidbody.velocity = Vector3.zero;
}
}
}
Thank you for your help!