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 gilgada · Apr 25, 2012 at 10:06 AM · rotationerrorvelocityintcatapult

Problem with updating an integer.

I have a gameObject that I am trying to get the rotation.x of. This is then to be saved to an integer called velocity. The problem is, I am getting the 'Expressions in statement must only be executed for their side-effects" error. I know this means that my code isnt doing anything and this may be due to C# handling the integer in a certain way that is different to unityscript.

The code is as follows:

var changeType : changeMaterialType; var catapult : GameObject; var velocity : int;

function Start(){ velocity = 0; }

function Update () {

velocity == catapult.transform.rotation.x;

if(rigidbody.isKinematic == false) { if(constantForce.force.y >= -50) { gameObject.constantForce.force.y -= changeType.currentProjectile.rigidbody.mass * 10/velocity; }

 if(constantForce.force.z <= 10 && constantForce.force.z >= 0)
 {
 gameObject.constantForce.force.z += 1;
 }
 if(constantForce.force.z == 10)
 {
 gameObject.constantForce.force.z -= 2;
 }

} }

I have the velocity int starting at 0 and want it to be equal to the rotation of my catapult gameobject when updating.

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

1 Reply

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

Answer by BiG · Apr 25, 2012 at 10:11 AM

This line is strange:

 velocity == catapult.transform.rotation.x;

since it's a double "=" outside an if statement. It should be

 velocity = catapult.transform.rotation.x;

But I'm not sure this will solve all your problems.

Comment
Add comment · Show 8 · 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 gilgada · Apr 25, 2012 at 10:14 AM 0
Share

thanks i must have overlooked this. the problem now is that the velocity int is just staying as 0 all the time

avatar image BiG · Apr 25, 2012 at 10:20 AM 2
Share

Stupid question: is rigidbody.is$$anonymous$$inematic setted to false? It's the only way to work :) By the way, I wish to tell you another thing: the second inner if (if(constantForce.force.z == 10)) will never be executed: look at the first inner one, and you'll see that the case z=10 is already considered.

avatar image gilgada · Apr 25, 2012 at 10:24 AM 0
Share

the rigidbody is user controlled for a time at the start of the game and is therefore kinematic. it is then changed to false when firing it as it should then be affected by the constant force.

avatar image gilgada · Apr 25, 2012 at 10:51 AM 0
Share

do you know why my velocity int is always set at 0? even at runtime, it does not update to the rotation of the catapult which can be seen to change when paused.

avatar image BiG · Apr 25, 2012 at 10:57 AM 0
Share

Glad you solved!

Show more comments

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

why can't i divide rb2D.velocity.x by rb2D.velocity.x? [Fixed] 1 Answer

Velocity bug with hinge joints forces in C# 0 Answers

2D sprite rotation with velocity and interpolation 1 Answer

Random Rotation around given axis 0 Answers

Rolling sphere keep velocity but slow rotation 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