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 /
avatar image
1
Question by Cookiemonster · Sep 23, 2011 at 11:12 PM · c#quaternionrotateif

if & Quaternion

Hi there, and thanks for your attention. Im (very) new to c# and im trying to write my first script that moves a character. The script activates on a keycode, and when it has a certain y rotation, it will move. Otherwise, it will rotate towards this y rotation.

A part of my script goes like this:

public void move_Left(){    
    if(transform.rotation == Quaternion(transform.rotation.x,270,transform.rotation.z,transform.rotation.w)){
        transform.position = new Vector3(transform.position.x - 5,transform.position.y,transform.position.z);
    } else {
        transform.rotation = new Quaternion(0,270,0,transform.rotation.w);
    }    
}`
The problem is that i get an error that says : "error CS0119: Expression denotes a type', where a variable', value' or method group' was expected" How can I fix this ?? thanks

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

2 Replies

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

Answer by aldonaletto · Sep 23, 2011 at 11:56 PM

The quaternion components x, y and z have nothing to do with the rotation angles around axes x, y and z - you should use transform.eulerAngles instead. Another point: it's better to allow a small error margin to accept the 270 degrees angle; you probably could never rotate the object manually to a precise 270 degrees rotation, and anyway comparing floats hardly produces an equality.

float error = 1.5f; // accept the angle if inside this error margin

public void move_Left(){ float angleY = transform.eulerAngles.y; if (angleY < 0) angleY = 360 + angleY; // y may come as -90 instead of 270 if (Mathf.Abs(angleY - 270) < error){ // accept values inside +/- range transform.position = transform.position + new Vector3(-5, 0, 0); } else { transform.rotation = Quaternion.Euler(0, 270, 0); }
}`

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 aldonaletto · Sep 24, 2011 at 10:44 AM 0
Share

@Cookiemonster wrote:
Sorry for the late reply :) Thanks alot, and I can see why it doesn't have anything to do with Quaternion now. Thanks alot.

How do I close this question ??

avatar image
0

Answer by J3-Gaming · Sep 23, 2011 at 11:50 PM

You forgot the new keyword in your if statement.

 if (transform.rotation == new Quaternion(transform.rotation.x, 270, transform.rotation.z, transform.rotation.w))
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Always rotates 0 when setting values 1 Answer

How i can equal 2 Tranform Rotations? 1 Answer

How do I rotate a Rigidbody to a surface normal AND use camera rotation? 1 Answer

Distribute terrain in zones 3 Answers

transform.Rotate not working beyond 90 / 270 degs with RigidBodies (bug?) 2 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