- Home /
GameObject won't move after got child
Sorry for the basic question, I am quite new in unity. So I use the FPS Controller from Unity. That is also my parent game object. I have another game object which is a book with the script down below..
So the problem is that after I set the parent of the book. I cant move.... I don't get an error or something.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityEngine.UI;
public class bookCollider : MonoBehaviour {
FirstPersonController playerController=null;
public Text clicktext;
private bool isInTrigger=false;
GameObject gameControllerObject;
void Start(){
gameControllerObject = GameObject.FindGameObjectWithTag ("FirstPersonController");
if (gameControllerObject != null)
{
playerController = gameControllerObject.GetComponent <FirstPersonController>(); //here is the error
}
if (playerController == null)
{
Debug.Log ("Cannot find 'FirstPersonController' script");
}
}
void Update(){
if (isInTrigger) {
if (Input.GetKeyDown (KeyCode.F)) {
gameObject.SetActive (false);
clicktext.text = "u picked that item up";
Invoke ("setTextToDefault", 2f);
}
if (Input.GetKeyDown (KeyCode.I)) {
this.transform.parent = gameControllerObject.transform; //after here I cant move backwars/forward/sideways
clicktext.text = "added to int";
Invoke ("setTextToDefault", 2f);
}
}
}
private void setTextToDefault(){
clicktext.text = "";
}
void OnTriggerEnter(Collider other) {
// Destroy(gameObject);
// playerController.PlayJumpSound ();
clicktext.text=" f:pick up item.I:add to inventar";
isInTrigger = true;
Debug.Log ("jojojo");
}
void OnTriggerExit(Collider other) {
clicktext.text="";
isInTrigger = false;
Debug.Log ("lol mate u out");
}
}
What are your settings for the book collider and rigidbody?
Answer by FortisVenaliter · Jul 09, 2017 at 03:25 PM
Most likely, the collider in the book is blocking the controller from moving. Try setting the colliders to triggers when the book is parented.
FortisVenaliter how excactly do I do this. I am quite new.
On the collider, check the trigger box. you may also need to change your function to trigger ins$$anonymous$$d of collider.
Edit: it seems that you are already using triggers in your script.
TheReEvolutions my book is by default a trigger. not only when I parent it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125840im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I reference the transform component of a gameObject to a script automatically? 0 Answers
Strange movement artifacts when rotating children around parent object 1 Answer
Silly Instantiation Issue 0 Answers
Parent object is getting generated why ?? 1 Answer
Changing the parent of an object gets rid of its parents? 1 Answer