i need a direction to start, if there is some example then it will be fabolous…what i’m looking for is—
my third person is roaming in a scene and it reaches a particular point[i dont know what to call, a plane, a collider , rigid body], so when it reaches this point, a cube should fall in front of him …
what things i need, if there is something like some code, please guide me
Typically this would be done using a collider that’s been marked as a trigger, the OnTriggerEnter() callback (for detecting when the player has entered the specified area), and the Instantiate() function (to create the cube).
There’s lots of examples on the forums and elsewhere of how to make something happen when a trigger is intersected; searching the forums for ‘ontriggerenter’ will probably turn some of them up.
Meanwhile though, try breaking the problem down until you get to something that you know how to solve, and then work your way back up from there.
Let’s start here: do you know how to create a game object and add a collider to it?
If I understand correctly you want to:
1- player to enter a trigger
2- when event #1 happens, have an object drop in a pre-determined location
theres a few ways to go about this but one way is the following:
1- place a script on the trigger; it will have to use the following function: Unity - Scripting API: Collider.OnTriggerEnter(Collider)
Inside that function you will have to write the code for what you want to have happen, or you can send a message with some data to another script.
2- place a script on the falling object that needs to fall when the player activates the trigger; the script will have to have code to either move the object down to a certain position: Unity - Scripting API: Mathf.MoveTowards
Or you can use instantiate to create the object at runtime and as long as it has a rigidbody component, it can fall and land on the floor: Unity - Scripting API: Object.Instantiate
Thats pretty much it. However, based on your earlier responses to this thread, I have the feeling you are not familiar with scripting too well? If that’s so, I recommended researching and learning scripting a bit more so you are at the point where you’re comfortable looking through the scripting reference, looking at examples, and writing your own code. On a good note, what you are trying to do is very easy and should be feasible even for beginners to Unity Scripting. If you still have trouble, feel free to ask some more questions.
hiii, thanks I3D , i am new to scripting, i have started it a month ago though but an hr daily to the max, from the last few days i am spending more than 3 per day and now i am getting familier to things… i followed the walker boys tutorial till project 2, so have a good idea of things…
As every one has their way of learning, so i am adopting mine, i have given myself 26 tasks to do , i have completed 4-5 in 3 days and i know the day 26th is ended i’l be able to turn things on my own…so i m struggling buttt with people like u and this incredible forum , great users i am still moving
Cool, enjoy working on your project, as scripting can be a lot of fun. I’m scripting an FPS weapon system at this moment and it’s coming along nicely; just got a 3 part particle system working for the firing/muzzle flash effect and tracer fire.
If you have any other questions, feel free to ask.
i have attached a script to the cube and when TPS enters the area, i see the “Hello” on my console message…means all is going good…
now inside this function , shall i add the mathf script or create a seperate script and attach it to sphere ? if this is so then how do i call that script inside OnTriggerEnter function ?