Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Feb 16, 2016 at 02:41 PM by _joe_ for the following reason:

Out of scope question

avatar image
0
Question by vespa39 · Nov 22, 2015 at 03:49 AM · vector3error message

i am making a mario clone in my class and i keep getting this error (11,52): error CS0029: Cannot implicitly convert type `UnityEngine.Vector3' to `float'

if anyone can help me out would be appreciated, does it mean you can't use a vector3 in this line of code? I wrote it out just like my teacher put it, but not sure why am getting the error - and of course I can't move on with the assignment without fixing this error - I have rewritten it many times just in case I missed something - but still get the error code.

thanks in advance

using UnityEngine; using System.Collections;

public class Camerafollow : MonoBehaviour {

public Transform target; public Transform leftBounds; public Transform rightBounds;

public float smoothDampTime = 0.15f; private float smoothDampVelocity = Vector3.zero;

private float camWidth, camHeight, levelMinX, levelMaxX;

// Use this for initialization void Start () {

camHeight = Camera.main.orthographicSize 2; camWidth = camHeight Camera.main.aspect;

float leftBoundsWidth = leftBounds.GetComponentInChildren ().bounds.size.x / 2; float rightBoundsWidth = rightBounds.GetComponentInChildren ().bounds.size.x / 2;

levelMinX = leftBounds.position.x + leftBoundsWidth + (camWidth / 2); levelMaxX = rightBounds.position.x - rightBoundsWidth - (camWidth / 2);

}

// Update is called once per frame void Update () {

if (target) {

float targetX = Mathf.Max (levelMinX, Mathf.Min (levelMaxX,target.position.x));

float x = Mathf.SmoothDamp(transform.position.x, targetX, ref smoothDampVelocity, smoothDampTime);

transform.position = new Vector3(x, transform.position.y, transform.position.z); } } }

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 vespa39 · Nov 22, 2015 at 03:55 AM 0
Share

here is a shorten version of my question -

this is the error I keep getting Assets/scripts/Camerafollow.cs(11,52): error CS0029: Cannot implicitly convert type UnityEngine.Vector3' to float'

for this line or code - private float smoothDampVelocity = Vector3.zero;

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by NoseKills · Nov 23, 2015 at 07:23 PM

Doesn't that look weird to you :) ? float x = Vector3.something

Ask yourself this: what do you expect the value of some float to become when you try to put a Vector3 (consisting of 3 floats) into it ? I guess '0' in this case since the name of the Vector3 variable happens to be "zero", but just as well you could be doing

private float smoothDampVelocity = new Vector3(-3, 6, 10);

What would the float value become then ? -3, 6 or 10 .... or 10-3+6 ? And how could the compiler know ?

The compiler doesn't know how to make 1 float out of the Vector3 you are trying to put into it. If you want your float to be "0", just do private float smoothDampVelocity = 0f; Otherwise you have to do some more coding to tell the compiler what number to store in your float variable every time you assign a Vector3 into it.

There are strict rules for what types pf data you can store in different types of variables and what types can be converted to other types

https://msdn.microsoft.com/en-us/library/ms173105.aspx

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
avatar image
0

Answer by vespa39 · Nov 27, 2015 at 10:10 PM

I appreciate you answering my question - am still very new to scripting, I will try what you suggest and hope it works -

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

37 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Normalize(); help 0 Answers

Problem with Crouch Script - 3D C# 2 Answers

What is causing my Spawner script to break Unity? 1 Answer

Position is infinite 0 Answers

NullReferenceException: Object reference not set to an instance of an object 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