have a script effect the object its attached to
I have this script attached to a game object.:
public class Flight : MonoBehaviour {
public int height = 2000;
void OnTriggerEnter ()
{
(this gameoject ( Vector3.up * height)
}
}
the Idea being that when a Rigidbody enters the trigger the object that this is attached to will go up into the air, any help greatly appreciated.
Answer by CirseiHyuga · Jan 25, 2017 at 11:36 AM
void OnTriggerEnter(Collider col)
{
this.transform = new Vector3 (this.transform.x, this.transform.y, height);
}
this is the idea, but this will teleport your game object instead of make it move. many solutions : - you can use Rigidbody.AddForce(float force) until a specific height. -You can start a coroutine which will move the object with Mathf.Lerp -You can also take a look at the effectors.
I would suggest you to watch the tutorials on the unity site here for scripting and here for physics.
Please vote for me :)
Thanks for your help :) I've ended up with this:
void OnTriggerEnter( Collider col) { this.transform = new Vector3 (40, 10, 40); } }
I keep getting the error saying that I can't because it's read only?
EDIT: also ignore the values, for now, that's just me trying to see a reaction.
I made a mistake, because you want to change the position, it is this.transform.position....
Your answer
Follow this Question
Related Questions
Soccer game, more realistic net 1 Answer
Problem with destroying a gameobject 2 Answers
Fade Object Out On Scene Change 1 Answer
How can I change GameObject's texture? 1 Answer
How to find GameObject in script? 1 Answer