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 Skwardj · Jan 22, 2011 at 07:01 PM · rigidbodyvelocity

Need help with scripting (problem related to rigidbody/velocity)

Hello guys. Im making a 3D space ship game and i got a problem. Here's a piece of my code: Code:

velX+=Input.GetAxis("Horizontal")*sensStrafe;

if (Input.GetAxis("Horizontal")) { rigidbody.AddRelativeForce(velX,0,0); rigidbody.velocity=Vector3(Mathf.Clamp(rigidbody.velocity.x,-maxStrafe,maxStrafe),rigidbody.velocity.y,rigidbody.velocity.z); velXdir=0; } else { if (Mathf.Abs(rigidbody.velocity.x)>=0){ if (velXdir==0) { velXdir=velX/(Mathf.Abs(velX)); } rigidbody.AddRelativeForce(-1*stabStrafe*velXdir,0,0); velX=0; } }

Im moving my ship in horizontal axis using W and S keys. I want to make an inverted force that will appear right after the strafe engines are turned off to stabilise the ship. Variables i used and their purpose: velX - obvious sensStrafe - equals 1 atm. velXdir - equals velXdir/abs(velXdir). I used that to get the dirrection of the stabilisation force. stabStrafe - strafing speed, equals 0.5

Currently my ship got a fixed rotation and the only thing affecting it's transform is the velX.

Problems i get: 1. When im using velXdir in the rigidbody.AddRelativeForce(-1*stabStrafe*velXdir,0,0); im getting an error saying that the force i apply is (n/a,0,0) which means its absent as i understand it. The ship keeps strafing in the original dirrection. 2. When i dont use velXdir and just put rigidbody.AddRelativeForce(-1*stabStrafe,0,0); i get another error. Since this force is applied from the fixed side, i made my ship strafe right so the stabilisation force will occure from right to left. In fact it does occure but the problem is that the stabilisation force just makes the ship endlessly strafe to the opposite direction. As i understand, it means that the if (Mathf.Abs(rigidbody.velocity.x)>=0) isnt getting the "true" value which is a mystery for me.

Can anyone help me?

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

0 Replies

· Add your reply
  • Sort: 

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Calculating speed of rigidbody? 1 Answer

Set velocity of kinematic rigidbody appropriately 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Updating Velocity for a Rigidbody Collision 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