Help, player interaction with objects

I was thinking in ways to do the player’s interactions, then I started using triggers, so when the player enter the trigger, an action becomes avaliable. But I was wondering if theres other way to make these, because I want to implement enemy focused or target focused.

Well, you can trigger actions with the GUI System as well :slight_smile:

Could you explain a little bit more? What i want is to change a variable so the accion can be perform. Like if player is at a relative position from door, var door=1;// player can open door if button is pressed and var door ==1. But when I use vector 3 to measure a distance didnt work properly.

Hello, this should help you out :wink:

var doorGameObject : GameObject;

function OnGUI(){
    if(GUI.Button(Rect(0,0,100,100),"A button")){
        doorGameObject.doSomeActionBecauseYouPressedTheButton();
    }
}

hope it helps :wink:

The game I am creating is a 3d game, I want to make interactions like in the game shadow of colossus, for example: Wander close to Agro, makes posible interaction with the horse. Or something like Legend of Zelda or Okami, close to people makes avalible talk. Or close to ladder makes avalible climb. With the method you mentioned above I dont see how I can track distances or other vectors.

I guess I didn’t explain myself. The game I’m making is a Third person game. What I want to do is some kind of raycasting, so when the character is close enough to an object capable of interaction (ex:smile:oor, People), and the button of action in this case Key ‘X’ is pressed, the an action take place. This is something like the target on legend of zelda.

Maybe this will help you :
http://wiki.truevision3d.com/tutorialsarticlesandexamples/simple_ai_for_player_detection

It’s simple alghoritam form plyer detection.

Seams to be what I was looking for I will try this and if I get results I’ll let you know.

ummm… i don’t know why would you want to use raycast…
personally, i would use something like this function:

function CloseEnough(interactTag : String, distToInteract : float) : boolean {
	var allObjs : GameObject[] = GameObject.FindGameObjectsWithTag(interactTag); 
	
	for (var obj : GameObject in allObjs) { 
		var pos = obj.transform.position ; 
		var dist = Vector3.Distance(pos, transform.position);
		
		if (dist <= distToInteract)
			return true;
	} 
	
	return false;
}

so, to use this function, you would use something like:

function Update() {
	if(CloseEnough("Person", 2.0)) {
		// code to interact with peeople
	}
	
	if(CloseEnough("Ladder", 0.1)) {
		// code to interact with ladders
	}
}

i haven’t personally tried it, but i see no reason why it shouldn’t work… hope it helps you

The script that you mentioned above didnt work for me it show a warning, “interactTag is not defined”. But I created a layer with that name, and I still get the warning. So I dont know what can I do to correct that could you help me with that oennasr.

A tag isn’t the same as a layer. There is a tag popup in the inspector panel, just to the left of the layer popup.

Now its working, thanks for your help oennasr, andeeee.

gald i could help lol
(this is the first time that i actually helped someone in this forum… so happy! :smile: lol)