- Home /
pulling objects across collider
This script i attach to a collider and makes it so if any object enters it will be pulled along either the x, y, or z axis depending on what i want. i was wondering how to make it so the script will pull the object strait accros no matter where it enters. because right now if i have it set to be pulled allong the x axis any object that enters will be pulled along the x axis. but i want any object that enters just to be pulled stright accross the collider depending on where it enters, not a specific axis, hopefully that makes sence thanks!
private List<GameObject> pullObjects;
public Vector3 pullDirection;
public float pullSpeed;
void Start () {
pullObjects = new List<GameObject> ();
}
void Update () {
foreach (GameObject obj in pullObjects) {
obj.transform.Translate (Time.deltaTime * pullSpeed * pullDirection,transform);
}
}
public void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.gameObject.tag == "Untagged") {
Debug.Log ("object entered");
pullObjects.Add (coll.gameObject);
}
}
public void OnTriggerExit(Collider col)
{
if (col.gameObject.gameObject.tag == "Untagged") {
pullObjects.Remove (col.gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
pulling objects 1 Answer
pulling in objects one end, and releasing out the other 0 Answers
pulling objects across a collider 0 Answers
adding Up force 0 Answers
Model tips over for no reason 1 Answer