OnTrigger, look at

I have two GameObject, One with an Activate Trigger and the other One with a Deactivate Trigger. My 3D Object have a SmoothLookAt script to look at the camera, when the camera Activate Trigger the 3D object start to follow the camera, then the camera goes to the Deactivate Trigger then the 3D object stop right on the position where the camera touch the GameObject with the Deactivate Trigger.
I need that when the camera touch the Deactivate Trigger, the 3D object goes back to their original position, and not stays looking beside. How can i figure that.

I using this script, i need to created a new one or insert in this one?

You would need to store the position for later use in Start.

Also, using proper Code tags ([ code ]) would help us read a little better as it retains tabs. :wink:

using UnityEngine;

public class ActivateTrigger : MonoBehaviour {
	public enum Mode {
		Trigger = 0, // Just broadcast the action on to the target
		Replace = 1, // replace target with source
		Activate = 2, // Activate the target GameObject
		Enable = 3, // Enable a component
		Animate = 4, // Start animation on target
		Deactivate= 5 // Decativate target GameObject
	}

	/// The action to accomplish
	public Mode action = Mode.Activate;

	/// The game object to affect. If none, the trigger work on this game object
	public Object target;
	public GameObject source;
	public int triggerCount = 1;///
	public bool repeatTrigger = false;
	
	private Vector3 defaultPosition = Vector3.zero;
	void Start(){
		defaultPosition = source.transform.position;
	}

	void DoActivateTrigger () {
		triggerCount--;

		if (triggerCount == 0 || repeatTrigger) {
			Object currentTarget = target != null ? target : gameObject;
			Behaviour targetBehaviour = currentTarget as Behaviour;
			GameObject targetGameObject = currentTarget as GameObject;
			if (targetBehaviour != null)
				targetGameObject = targetBehaviour.gameObject;

			switch (action) {
				case Mode.Trigger:
					targetGameObject.BroadcastMessage ("DoActivateTrigger");
					break;
				case Mode.Replace:
					if (source != null) {
						Object.Instantiate (source, targetGameObject.transform.position, targetGameObject.transform.rotation);
						DestroyObject (targetGameObject);
					}
					break;
				case Mode.Activate:
					targetGameObject.active = true;
					break;
				case Mode.Enable:
					if (targetBehaviour != null)
						targetBehaviour.enabled = true;
					break;
				case Mode.Animate:
					targetGameObject.animation.Play ();
					break;
				case Mode.Deactivate:
					targetGameObject.active = false;
					targetGameObject.transform.position = defaultPosition;
					break;
			}
		}
	}

	void OnTriggerEnter (Collider other) {
		DoActivateTrigger ();
	}
}

Ok, i put it the script you did to the GameObject with a Deactivate Trigger, but my 3D Object goes to another positio, the name of my 3D object is cu. There is a way to specified the cu to goes to his start position.

look at the Start method… that should answer where the position is coming from. swap source for something else, or however u need to use it.

i put it instead of source, cu

but still going to another place.

All I can tell you is to Debug it. You need catch the position where you want it to be at, from the object you want that to be from, at whatever time you need it to be. If that changes mid game, then Start is not the place to put it. Since I dont know your game logic, I will not know where to put it. :wink:

I have Three GameObject, One with an Activate Trigger.script and the other One with a Deactivate Trigger.script, and another GameObject i rename it to cu with my 3D Object inside, and a SmoothLookAt script to look at the camera. The script is on cu. when the camera Activate Trigger the 3D object start to follow the camera, then the camera goes to the Deactivate Trigger then the 3D object stop right on the position where the camera touch the GameObject with the Deactivate Trigger.
I need that when the camera touch the Deactivate Trigger, the cu Object goes back to their original position, and not stays looking beside. Heres a pic for you ti understand.

Oh my, very hard to follow your English.

OK, first, you want to know where the camera touches the collider of the Deactivate trigger, then you need to move cu to that point, then you need to move cu to its original position?

yes, because, cu stay looking beside when the camera touches the collider of the Deactivate trigger. I would like to cu return to its original position.

I need to move cu, from where its start. looking to the front. cu does not have any kind of animation, just the smooth look at script.

then u want that line in Start to look like this:

defaultPosition = target.transform.position;

I am of course confused why you have target as an Object and not a GameObject, but I am sure u have your reasons.

I piut a video for you to now, ok. The link is bellow.

That really doesn’t fit what you are describing. You want that when the camera, touches 1 piece, your face starts looking at you. when it touches the next, it disappears. The whole time, your using a smooth look to make the face “face” the camera.

Now, the only point I dont get, is that you say… when I hit the next, I want to “move” the face to its original position, but nothing in your code says “move” it does say “rotate”

Are you asking it to return to it’s default rotation?

when I say (when I hit the next, I want to “move” the face to its original position) . Is the next invisible gameobject box, with the Deactivate Trigger.script. Is rigth behind the dog face. I call cu the bone that turns the head to look at the ARCamera.

This bone called cu, that rotate the dog neck, does not have any animation. Just have the starting position, that i show you in the video.

Maybe im doing the process wrong!

instead… try these:

private Quaternion defaultRotation = Quaternion.identity;

void Start(){
defaultRotation = source.transform.rotation;
}



targetGameObject.transform.rotation = defaultRotation;

works great, thanks you very much!!!