- Home /
Vector3 not receiving coordinates
I have a vector3 created in one script that tells the location of the player, and a vector3 in another script that is supposed to receive it, but the receiver keeps showing up as 0,0,0.
Here is the sending script:
var pos : Vector3;
function Update () {
pos = transform.position = Vector3(0, 0, 0);
}
and here is the receiving script:
var player : GameObject;
var looking = false;
var ply : Vector3;
var x : float;
var z : float;
function Update() {
x = Random.Range(1, 30);
z = Random.Range(1, 30);
player.GetComponent(Playerpos).pos = ply;
ply + Vector3(x, 0, z);
if(looking == false){
transform.position = ply;
}
}
function HitByRaycast(source : GameObject) {
looking = true;
}
EDIT: Benprodictions1: Since you don't seem to be capable enough to format your code yourself, I did it for you!!!
Answer by Benproductions1 · Jun 05, 2013 at 01:50 AM
Ok, lets desc check this:
"sending script"
-every update you set both pos and player position to Vector3.zero
"receiving script"
-every update
-You set sending script: pos to a random position
-You generate a new random position but don't assign it
-You set the position of the object of the sending script to a random position which never changes
I can't tell what this is supposed to accomplish, but I'm sure you can tell where you went wrong :)
Hope this helps,
Benproductions1
I was trying to make the script so whenever looking = false, the object would teleport to a random position near the player.
so basiclly:
if !looking
transform.position = player.position + randomPosition
Whats all the other code doing there???
Your answer
Follow this Question
Related Questions
crouch script 4 Answers
Spawn object at random position in front of player 1 Answer
Circle inside Circle 1 Answer
addition of vector3 1 Answer
Random placement objects. 0 Answers