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
0
Question by Overflo · Aug 17, 2012 at 03:33 PM · c#vector3collisionflags

Need help converting js to C#

I am new to Unity and i am trying to convert the CharacterControl script from the book "Unity 3 Game Development Hotshot". I have most of it but am having trouble with two things

JS - var v3_movement : Vector3 = (v3_moveDirection * f_moveSpeed) + Vector3 (0, f_verticalSpeed, 0);

C# - Vector3 v3_movement = (v3_moveDirection * f_moveSpeed) + Vector3 (0, f_verticalSpeed, 0);

The error i get is Expression denotes a `type', where a `variable', `value' or `method group' was expected

jS - public function IsGrounded () : boolean { return (c_collisionFlags & CollisionFlags.CollidedBelow); }

C# public bool IsGrounded() { return (c_collisionFlags & CollisionFlags.CollidedBelow); } the error here is Cannot implicitly convert type `UnityEngine.CollisionFlags' to `bool'

Any suggestions greatly appreciated

Cheers

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 Overflo · Aug 18, 2012 at 02:57 AM 0
Share

Thankyou both.

the Vector3 line is now good.

I know that the CollisionFlags doesn't look like it should work but it does in the JavaScript code. Even when i add the !=0 i still get the same error.

This is where it also appears in the code - I will show the JS version that works

declared at top of class

private var c_collisionFlags : CollisionFlags;

in the Awake() function

c_collisionFlags = CollisionFlags.CollidedBelow;

in the Update() function

c_collisionFlags = controller.$$anonymous$$ove(v3_movement);

then in the IsGrounded function (bool) as in first post

return (c_collisionFlags & CollisionFlags.CollidedBelow);

Cheers

avatar image Bunny83 · Aug 18, 2012 at 02:59 AM 0
Share

@Overflo: Don't post annotations as answers! Answers should answer the question. This is not a forum, this is a Q&A site.

I've converted your answer into a comment.

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Khada · Aug 17, 2012 at 03:54 PM

You're missing the 'new' keyword:

 Vector3 v3_movement = (v3_moveDirection * f_moveSpeed) + new Vector3 (0, f_verticalSpeed, 0);

The second one is more tricky. The & in c# is a bitwise AND. I'm not sure if it's the same in java (I suspect it is). Clearly 'CollisionFlags.CollidedBelow' isn't a boolian object and I can't see what type it is so it's hard to help here.

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 ScroodgeM · Aug 17, 2012 at 03:36 PM

 new Vector3 (0, f_verticalSpeed, 0)

instead of

 Vector3 (0, f_verticalSpeed, 0)


 return (c_collisionFlags & CollisionFlags.CollidedBelow != 0)

instead of

 return (c_collisionFlags & CollisionFlags.CollidedBelow)
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 Overflo · Aug 18, 2012 at 02:32 AM

Ahh I think I have it.

return (c_collisionFlags & CollisionFlags.CollidedBelow) != 0

instead of

return (c_collisionFlags & CollisionFlags.CollidedBelow != 0)

Thanks for your help

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 Spεci · Feb 08, 2013 at 02:36 PM

This one works with C#.

 public bool IsGrounded() { 
     return (controller.collisionFlags == CollisionFlags.Below); 
 }

Although it seems that there is something wrong with the using of "&". Even the Unity documentation

suggests the using of "&" with C# but it gives the error that you mentioned.

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

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

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

Distribute terrain in zones 3 Answers

private Vector3 function? 2 Answers

[Dublicated, delete] Need help converting js to C# 1 Answer

Multiple Cars not working 1 Answer

Vector3 is always subject to serious stutter in Translation 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