Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by TOFFster · May 24, 2014 at 11:47 AM · javascriptpositionobjectfloat

Saving Object Position in Float NOT Object

Hey,

So I'm new to Unity, as you can probably guess by the question I'm also new to Javascript. I'm finding this whole non static variable declaration lark to be more of a curse than a blessing. I'm trying to grab a sprite's position via x and y coordinates (2D) and use them in a calculation for velocity. However Unity tells me I cannot perform said operation on two "variables" of type object. Which is fair enough. I can't seem to figure out how to typecast these objects into float type variables, in Java it would have been simple enough but here, in javascript, I'm completely and utterly baffled.

Here's what I'm using to store the position values:

 characterPositionX = character.position.x;
 characterPositionY = character.position.y;

The variables declared like so:

 var characterPositionX;
 var characterPositionY;

I've tried using ": float" however I'm pretty sure that's purely to do with MonoBehaviour and not type casting(?). I'm honestly lost here, if anyone can offer up some help it'd be greatly appreciated.

Cheers, Lewis

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 tanoshimi · May 24, 2014 at 12:29 PM 0
Share

You're wrong - the : float bit is important :) But are you sure you need to separate out the x and y components? You should be able to calculate velocity working purely with Vector2 inbuilt functions (hard to say without seeing more of your code)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Xumbu · May 24, 2014 at 12:07 PM

with java background, why don't you use csharp?

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 TOFFster · May 24, 2014 at 12:14 PM 0
Share

I was considering it, and started using it but decided I would try a different language. I'm doing this for educational purposes rather than entertainment, so figured I'd learn a language that's different in structure to Java a little more than C# is.

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

21 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

Related Questions

Moving an object 0 Answers

Why Does My Object Change Position During Update? 0 Answers

How to move an object from one position to desired position? 0 Answers

'enabled' is not a member of 'Object' 1 Answer

2D get touch input 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