- Home /
I have no need for this information any more.
How Can One Collider Recognize Contact With Another?
I paint trees onto the landscape that have colliders, and am finding too much trouble with scripts that spawn trees as gameobjects (therefore the trees can have chopping scripts attached). I do have a question on that if you have an idea, though!
Another solution, which I don't have but am working on, is the script applied to the axe (or character) that recognizes if it is within range of a tree or collider, and destroys said tree/collider when a key is pressed. I would be very grateful if anybody who has an idea could post a comment, and anybody who has an answer could post an answer.
I have code here that may make the more basic parts require less thinking, so that if you are kind enough to try to answer, you will put your energy to more efficient use. I would be highly grateful for any help or reasonable effort at help.
//Finding A Key (Backspace)
if(Input.GetKeyUp(KeyCode.Backspace))
{
//Anything within these brackets is activated upon backspace
}
This script is my original script. It is what needs to be changed somewhere. I think that it is in the Update function when it defines new variables.
#pragma strict
/*
This script is currently applied to the tree in question
This script must be applied to the character or axe
It must recognise that it is hitting a tree via the tree's collider and then cut the tree down
One cannot depend on the tree to do anything that is hasn't yet done. It must all work with the character or axe
The character must have a detection of range so that it finds the tree, not the other way around
It must have a timer to cut down the tree after a certain amount of time
The animation is for later, but may be incorporated into this script
*/
var chopDistance = 5;
var inRange = false;
var chopTime = 0;
function Start () {
}
function Update ()
{
//This must be changed to find the tree, not the character
var player : Vector3 = gameObject.Find("Character").transform.position;
//This must be edited to look for the tree, not the player
var moveDirection : Vector3 = player - transform.position;
if (moveDirection.magnitude < chopDistance)
{
inRange = true;
}
if (inRange == true)
{
//This keycode must be changed to the LMB
if(Input.GetKeyUp(KeyCode.Backspace))
{
Timer();
}
}
}
//This function seems to need not a single edition
function Timer()
{
yield WaitForSeconds(chopTime);
Destroy(gameObject);
Player_Inventory.Players_Wood += 1;
}
Follow this Question
Related Questions
Ai that applies damage in collision? 1 Answer
Editing a variable from another script on collision 3 Answers
Damage on collision with player.. 1 Answer
Area of effect melee attack for 3rd person game? 1 Answer
PLease Help 1 Answer