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 /
This question was closed Apr 06, 2013 at 11:23 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by Sweawm · Apr 06, 2013 at 10:53 AM · movementvector3aivelocityconstructor

Vector3 Issues - Not Able To Solve Constructor issue

Alright, I've done my research into this issue, examined similar scripts and tested it, but I've hit an error with the Vector3 doesn't have a visible constructor. I found information that this is simply because I need to construct, that is, specify the property.

I believe I've hit a property I cannot specify, for some reason. I'm sure the error may be in the property lookDir (look direction), but no matter how much tampering, I cannot get Vector3 to accept it. The error specifically is BCE0024: The type 'UnityEngine.Vector3' does not have a visible constructor that matches the argument list '(UnityEngine.Vector3)'

with conflict with the line: myTransform.rigidbody.velocity = Vector3(lookDir.normalized MoveSpeed Time.deltaTime);

The script works perfectly if lookDir is replaced with transform.forward (but doesn't work fine in-game), so lookDir is certainly the issue.

If someone can offer advice on how to address the issue, and if kindly enough, offer a correction entirely, it would be much appreciated.

The actual script is below:

 var Player : Transform;
 var MoveSpeed = 4;
 var MaxDist = 10;
 var MinDist = 5;
 var myTransform : Transform;
 var distance = Vector3.Distance(Player.position, transform.position);
  
  
 function Awake(){
     myTransform = transform; 
 }
 
 function Update () 
 {
     if (distance <2f) 
     {
     
     var dist = Vector3.Distance(Player.position, myTransform.position);
  
     var lookDir = Player.position - myTransform.position;
 
         transform.LookAt(Player);
  
         if(Vector3.Distance(transform.position,Player.position) >= MinDist){
         
           myTransform.rigidbody.velocity = Vector3(lookDir.normalized * MoveSpeed * Time.deltaTime);
          
          if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
              {
    }
 }
 }
 }
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 Fattie · Apr 06, 2013 at 11:23 AM 1
Share

this is a duplicate question so I have deleted it. please do NOT post duplicates, to avoid wasting the time of the many dedicated board members! thanks

1 Reply

  • Sort: 
avatar image
0

Answer by Benproductions1 · Apr 06, 2013 at 10:58 AM

Hi! there,

Your problem is that your trying to create a Vector3 from a Vector3. As the debug message tells us, none of the constructor for Vector3 take a Vector3 as an argument.

The cool thing is you don't need it at all! Any calculation with a Vector3 that is legal, automatically yields a Vector3, so:

 Vector3 * float = Vector3
 Vector3 / float = Vector3

Therefore your line should be:

 myTransform.rigidbody.velocity = lookDir.normalized * MoveSpeed * Time.deltaTime;

There is no need to tell unity the outcome of a calculation, it's all built in :)

Hope this helps, Benproductions1

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

12 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

Related Questions

How to keep velocity and add onto it from any rotation. 1 Answer

2D Enemy chasing player not at a constant speed,Enemy following player at constant speed 0 Answers

Random direction with Mouse Click... 2 Answers

How to stop player velocity completely 1 Answer

Change in position going up not smooth 1 Answer


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