- Home /
Question by
Ecoste · Nov 09, 2014 at 09:00 PM ·
javascriptrocket
GetRelativePoint, GetRelativeVector doesn't work.
Hello, for some reason those 2 functions don't work on my rigidbody2D of a rocket.
They always return 0,0.
This is my code
#pragma strict
var rocket : GameObject; //Prefab
function Start () {
}
function Update () {
}
function OnTriggerEnter2D(obj : Collider2D){
if(obj.name == this.name){ //If rocket goes into a no-no zone, I want to destroy it and spawn some more rockets going into another direction.
spawnRockets(obj.gameObject);
//Debug.Log(rocket.rigidbody2D.GetRelativePoint(Vector2(0.01,0.01))); //The Rocket is correct, just get relative point doesn't work.
Destroy(gameObject); //Works
Destroy(obj.gameObject); //Works
}
}
function spawnRockets(obj : GameObject){
//0 Degrees
var a = Instantiate(rocket, gameObject.transform.position , Quaternion.identity); //Creates another rocket.
a.GetComponent(Rocket).destination = rocket.rigidbody2D.GetPoint(Vector2(100,100)); //Works, but since the GetPoint returns 0,0 it doesn't work correctly.
Debug.Log(obj.name); //Gets the correct name, I give all my rockets a unique name.
Debug.Log(a.rigidbody2D.GetRelativeVector(Vector2(0.01,0.01))); //Doesn't work no matter how I spin it. Returns 0,0
}
Anyone know what the problem might be?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613171116im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
How to rotate object 180 degrees smoothly 2 Answers
How to connect two functions (Javascript) 1 Answer
int.parse with decimal? 1 Answer