Search Unity

Can this Grappling hook code not just instantly teleport them but pull over time?

Discussion in 'Scripting' started by R3DRAW STUDIOS, Aug 31, 2014.

  1. R3DRAW STUDIOS

    R3DRAW STUDIOS

    Joined:
    Aug 18, 2014
    Posts:
    37
    here is the code all it does is teleports you directly to where you click i want it to pull you there over time (depends where you click how long it would take to get there.

    Optional:If you would like to could you also make it so player can like be able to spin rope around in circles around an object.) remeber this is optional you dont have to do it.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public class PlayerWeapon : MonoBehaviour
    5. {
    6.     public Transform Player;
    7.     public GameObject Hook;
    8.     //public Transform Rope;
    9.     private GameObject HookChild;
    10.     //public Transform RopeChild;
    11.     void Update ()
    12.     {
    13.        Ray HookRay = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
    14.        Debug.DrawRay(HookRay.origin,HookRay.direction,Color.green);
    15.        RaycastHit HookHit;
    16.        if (Input.GetMouseButtonDown(0))
    17.        {
    18.          HookChild = null;
    19.          if(Physics.Raycast(HookRay, out HookHit))
    20.          {
    21.               Debug.DrawRay(HookRay.origin,HookRay.direction, Color.red);
    22.               HookChild = Instantiate(Hook,HookHit.point,Quaternion.identity) as GameObject;
    23.               Player.localPosition = HookHit.point;
    24.               Debug.Log("Hook was hit");
    25.          }
    26.        }
    27.        if (Input.GetMouseButtonUp(0))
    28.        {
    29.             if (HookChild != null)
    30.                 Destroy(HookChild);
    31.         }
    32.     }
    33. }
     
    Last edited: Aug 31, 2014