- Home /
This question was
closed Apr 21, 2018 at 02:53 AM by
Jdogmaster.
pulling objects across a collider
this script i attach to a collider and it pulls objects accross the colliders axis i chose. so if i set it to x axis any object that enters world travel along the colliders x axis at a speed i chose. but i want any object that enters just to move across the collider without following an axis. how can i do this? here is the script i attach to the colliders. @Priyanka-Rajwanshi @Bunny83 @Kilsnus @davidcox70 @oroora6_unity
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") {
pullObjects.Add (coll.gameObject);
}
}
public void OnTriggerExit(Collider col)
{
if (col.gameObject.gameObject.tag == "Untagged") {
pullObjects.Remove (col.gameObject);
}
}
Comment
Follow this Question
Related Questions
pulling in objects one end, and releasing out the other 0 Answers
sucking in particles 3 Answers
pulling objects 1 Answer
adding Up force 0 Answers
adding force 1 Answer