I need to write a script that keeps everything and anything that falls out of the game world in the game world I need a script that preferably attaches to an object and reads objects with a certain script attached and sends whatever touches the attached object to the object with the other script that is directly above whatever falls out of the game world. so if anything falls out of the world it touches a plane below and gets sent to the nearest cell above it when it touches that plane. I have absolutely no idea how to do this though.
have you used the OnTriggerEnter function before? if not, start there… if you have; can you explain a little more clearly the structure of the “cells” and how you have setup your scene so we can help a little more?
I have used OnTriggerEnter about as much as I have used everything else. I understand what it does at least. I do not have alot of experience though. I have made my cells by hand in blender and they are basically just static objects placed in a grid and they are 46 by 46 "units apart, I did not use any of unity’s default terrain, not sure what else you might need to know.
at the moment all I really would know how to do is make the main cameras y value increase but that does not exactly help when the terrain is too far up they would get stuck in a loop of falling and being placed back below the surface or when the terrain goes up or way too far down, I do not want anyone to suffer falling damage if they fall out of the game, just to be placed back onto the cell. and I could not figure out how to target all items that hit the plane that I attached my script to but I am sure that part must be easier, I am probably just overthinking something there.
Hey, yourking77,
It’s a simple OnTriggerEnter(),
Then set the transform to a new position above the grid
here is a scene for you to look at
2678344–189199–FalloffEdge.unitypackage (7.72 KB)
Thank you I have taken a look at that and am sort of disappointed with myself that I did not think of that, it is so simple. I was thinking I needed a huge plane and then detect what cell the player is standing under. but all I really need is a plane the size of each cell, I was way over complicating things. thank you for the test scene, I appreciate it the help.
no problem, keep the easy questions coming!
How do I make it so that when anything touches it, it gets sent back to the desired position?
using UnityEngine;
using System.Collections;
public class WorldBoundsScript : MonoBehaviour {
//The game bounds that if anything touches the script will activate.
public GameObject cell;
Vector3 cellVector = new Vector3(1, 1, 1);
void Start() {
cellVector = cell.transform.localPosition;
}
void OnTriggerEnter () {
transform.position.y = cellVector.y + 2; //Error on this line
}
}
void OnTriggerEnter (Collider other) {
17. other.transform.position = cellVector.y + 2; //Error on this line it will not let me use other
18. }
you also need to have a box collider on the object, in the box collider check the box to set it as a trigger object
I will keep that in mind when I add objects in, I see what I missed the Collider other in the void thingy. I will test and see what I can come up with.
Awesome I got it working for the player. my inventory system is a long ways away so I cannot test that yet though, will a rigidbody on the object also make it work? or does it have to be some sort of a collider set to a trigger?
any object that collides with the trigger object will work. The rigidbody allows gravity to work and puss the player down to the trigger object. I’m not sure how an inventory system would need to do this. but hey it’s your game. normaly inventory systems are gui objects with scripts.
I meant like objects that you can pick up, the stuff that will go in your inventory you will be able to drag around and move and decorate houses or store ect. if they fall through I do not want to lose em forever so I wanted them to be affected by the script as well. but I guess I do not know why I was worrying about that that should be easy. got alot on my mind today I guess.
you’ll have to send me a screen shot or two of your project some day.