- Home /
Picking up Objects in a 2.5D game. Help!
I am having trouble finding any tutorials of answers on how to even begin to set up a pick up object script in my game. My game is simple and so is my objective. I have one GameObject with a character controller attached the Lerpz PlatformerController script. This is the player and I want this player to be able to pick up objects in my game in real-time i.e hover infront of the character and be able to place them in other areas in the game stage.
If there is a tutorial or simple script/method I can work with I would greatly appreciate it and to see the project so far for an idea of what I am working please follow this link.
http://www.youtube.com/watch?v=kc2jduUTt1c
This is just a demo and my game premise is slightly different, I want the pink ball to be trapped by locked doors (similar to the yellow ones in the demo) but the green ball to pick up objects (Keys) and place them in triggers to unlock the doors.
Thanks
UPDATE
I have been trying this code
function OnTriggerEnter (other : Collider){
if (other.CompareTag("Player"))
{
other.transform.parent = transform;
}
}
and have been attaching it to my Player. Yet when my Player touches the Object that is the trigger the Player becomes a child of that object. I want it to be the other way round yet when I try and change the CompareTag to "Object" (The name of the item I want to pick up) it says that the TAG HAS NOT BEEN DEFINED although that Game Object is name "Object".
Any ideas where I am going wrong?
Answer by Dave 11 · May 09, 2011 at 07:00 PM
At the collider of the object you want to pickup tick the box is Trigger, then use the function onTriggerEnter() { //do stuff, run checks, etc. } and attach this to your player character.
Edit: Nothing sounds nooby, I'm still learning myself too :) I assume you actually want to attach it to your player?
function OnTriggerEnter (other : Collider){
if (other.transform.name == "NameOfTheObjectToBePickedUp") {
other.transform.parent = transform.Find("TheObjectYouWantToMakeItAChildOf");
}
}
Im sorry if this sounds nooby but can you elaborate a bit more. I understand the onTriggerEnter statement but in terms of the command after I am a little lost. How would I begin to parent it? I was trying to use this script but do not know if it is the right direction for what I want?
function OnTriggerEnter (other : Collider){ if (other.transform.tag == "$$anonymous$$oveable") { other.transform.parent = transform.parent; } }
Cheers very much, I had been working with the script above on my UPDATE and was only a tiny variation to what you said. SO nearly go there ;)
Thankyou much I appreciate it :)