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 12, 2015 at 09:08 AM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Apr 12, 2015 at 08:54 AM · transformterrainpositionfloatint

What the hell? Cannot convert float to int PROBLEM.

Why is this not working?

This is basically trying to get the heights of a certain point in the terrain, but that last part ("Get heights") is causing a cannot convert to int issue.

Full error " error CS1503: Argument #1' cannot convert float' expression to type `int'"

Its basically the positions bPosX1 and bPosY1... it simply wont work if I put them into the get heights. Without the getheights code everything works fine. So the convertion part of bpoX01 and bposY01 seems to be fine.

             float bposX01 = bZone1.transform.position.x;
         float bposZ01 = bZone1.transform.position.z;
         float bposY01 = GameObject.Find("Terrain 0 3").GetComponent<Terrain>().SampleHeight(new Vector3(bposX01, 0, bposZ01));
         
         Vector3 nPos = (transform.position - terrainObject.gameObject.transform.position);
         Vector3 crd;
 
         crd.x = nPos.x / ter.terrainData.size.x;
         crd.y = nPos.y / ter.terrainData.size.y;
         crd.z = nPos.z / ter.terrainData.size.z;
 
         bposX01 = (int) (crd.x * terrain.terrainData.heightmapWidth); 
         bposY01 = (int) (crd.z * terrain.terrainData.heightmapHeight);
         //Offset...
         int ost = Inst1._size / 2;
         
 
 
 //Get heights.
 
         float[,] hPoints = ter.terrainData.GetHeights(bposX01-ost, bposY01-ost, size, size);             
 

Please help... thanks.

Comment
Add comment · Show 2
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 DeadKenny · Apr 12, 2015 at 09:03 AM 0
Share

Huh I seemed to have fixed it by adding this to the problem line.

      float[,] hPoints = ter.terrainData.GetHeights((int)bposX01-ost, (int)bposY01-ost, size, size);             

I wont accept as answer because I'm not sure this is the correct way to solve it.

Is it?

... I'm scared.

avatar image DeadKenny · Apr 12, 2015 at 09:08 AM 0
Share

Ok cool seems right I will accept one of yours rather.

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Apr 12, 2015 at 09:02 AM

 float[,] hPoints = ter.terrainData.GetHeights(
           (int)bposX01-ost, (int)bposY01-ost, size, size);
Comment
Add comment · Show 1 · 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 DeadKenny · Apr 12, 2015 at 09:08 AM 0
Share

Ok thanks. Both of you.

avatar image
0

Answer by Addyarb · Apr 12, 2015 at 09:01 AM

Replace line 30 with

  float[,] hPoints = ter.terrainData.GetHeights((float)bposX01-ost, (float)bposY01-ost, size, size);             

That should work. You are defining bposX01 and bposY01 as integers above, and calling them as floats later. You must do a conversion or else you'll usually get that error.

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

20 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

Related Questions

transform.position as variable to lock object 0 Answers

seperation of prefabs with two dimensional terrain generation 0 Answers

transform.position = new Vector 3 NOT moving to correct position? 1 Answer

Convert terrain map coordinates (GetDetailLayer) into world position 0 Answers

Accurate placed object's transform messes up on game start 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