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 neko_san · Oct 24, 2011 at 08:34 PM · rigidbodyinput

Moving a spaceship

Hello guys

I'm trying to make a small ship game, where the ship floats a bit above the ground, and of course you can move it forward/backward using the arrow keys, and also turn left/right. Think of the ships in WipeOut.

Since I'm new with Unity and I want to test stuff first, what I did was create a cube, set it as a rigidbody, then added a box for collision. All is fine and the object collides with the track mesh.

My question is, how do I apply movement to the ship?

In my code so far I have something like this:


function FixedUpdate () {
  forward = Input.GetAxis("Vertical");
  //Debug.Log ("Moving forward"+forward+" with deltatime="+Time.deltaTime);
  if (forward)
      rigidbody.AddForce(Vector3.forward * 5000 * forward * Time.deltaTime);
}

This seems to push the ship forward, although irregularly (it's more like it's going over a rocky terrain rather then a plain terrain) and of course it does not use the "ship's"(cube's) forward vector (Z axis). Once it collides and the cube rotates, pressing Arrow up does not move the cube forward but sideways. Do I or how do I specify that it should use the ship's Z axis always, and to make the movement constant over a period of time (say 10 meters/second). Do I use Time.deltaTime or something else since I use FixedUpdate and not Update?

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
0

Answer by Persona · Oct 24, 2011 at 08:52 PM

Use the rigidbody to disable the rotations that you don't want. Fixed Update updates itself far less than Update, so it will be rocky. Move it to Update().

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 FLASHDENMARK · Nov 04, 2011 at 07:39 PM 0
Share

No, the optimal solution is to have your physics code inside FixedUpdate(), and logic inside Update().

avatar image
0

Answer by Kingslash · Nov 04, 2011 at 07:31 PM

You could also try using AddRelativeForce instead of AddForce. It might be that your forces are being applied based on world instead of local coordinates.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't move player with rigidbody.velocity 1 Answer

AddTorque doesn't rotate? 3 Answers

How do i get the cube to turn when up and right or left arrow is pressed? 1 Answer

Jump Input Sensitivity 0 Answers

Add force in direction to camera 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