Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by Cbjfan1 · Jun 05, 2013 at 12:43 AM · positionvector3random

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!!!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Jun 05, 2013 at 01:43 AM 0
Share

Please format your code

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cbjfan1 · Jun 05, 2013 at 02:13 AM 0
Share

I was trying to make the script so whenever looking = false, the object would teleport to a random position near the player.

avatar image Benproductions1 · Jun 05, 2013 at 02:19 AM 0
Share

so basiclly:

 if !looking
     transform.position = player.position + randomPosition

Whats all the other code doing there???

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges