Search Unity

Pulling gameobject with PlayerController

Discussion in 'Scripting' started by wtsang01, Dec 5, 2013.

  1. wtsang01

    wtsang01

    Joined:
    Dec 4, 2013
    Posts:
    8
    Hi, im trying to have a gameobject pull my player with built-in player controller.

    PullingObject.js
    Code (csharp):
    1. function OnTriggerStay(hit : Collider) {
    2.     Debug.Log("thit"+hit.nameS);
    3.     if (hit.name.Equals("Player")) {
    4.         Debug.Log("trigger stay player.");
    5.          var object : GameObject = hit.gameObject;
    6.          //object.rigidbody.velocity += (transform.position - object.transform.position).normalized * gravity * Time.deltaTime;
    7.    }
    8.  
    9. }
    The Player can be on ground and in air, and I still want this effect to happen.
    $Capture.PNG
    So far, this code is able to detect my player, but my player isn't a rigidbody and I have read that it shouldn't be rigidbody. How would I make my character be pulled to this object but still able to move with the default controller? Thanks in advance.
     
    Last edited: Dec 5, 2013