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 kirax105strike · Jan 29, 2014 at 07:51 AM · movementgravityspacefriction

Space enviroment movement

I have a top down space shoot game that is currently allowing movement in all directions. That is front, back, side to side, and diagonal. All my movements are working correctly but I am wanting to implement space like physics to the game to where if my ship is traveling forward and I let go of the forward button my ship should still be drifting in the same direction. This needs to be the same for all directions even diagonal. I've tried using

transform.position += transform.forward * driftSpeed * Time.deltaTime;

which works for forward and diagonal movements since the ship is pointing in the direction it is going. However, if I am strafing side to side or in reverse the ship drifts in the direction the front of the ship is pointed. Is there a way to apply this drift in the direction the ship is currently heading instead of where the front is pointing? Btw I am currently using transform.Translate for my movements instead of rigidbody.

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
Best Answer

Answer by Headworker · Jan 29, 2014 at 04:16 PM

Well Ive been be doing similar movement in several projects now, and my advice would be to use the built-in physics engine, because it gives you everything you need in a matter of minutes.

Just set up a moving rigidbody and apply force to it, then tinker with mass / drag / angular drag, until you got the behaviour you want. You should go with a very low drag/angular drag for this kind of movement.

(in addition to what Otsego said) If you want to use direct movement however, the route to go would be to store the driftspeed as a Vector3 and and to assign the controller movement vector to it, each time a control event happens. It will be a bit of waste of time and work though, as the physics engine can simulate this much more easily and will give you a very smooth inertia system.

Another way of doing this code-wise would be to use a coroutine to monitor the current movement vector and add it in a decreasing fashion to the next movement step. But Id recommend to use the physics engine!

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 OtsegoDoom · Jan 29, 2014 at 04:22 PM 0
Share

I would actually go the route of Physics as well. It would really simplify things and it's quick to adjust.

avatar image
0

Answer by OtsegoDoom · Jan 29, 2014 at 03:20 PM

Currently you're adding a forward vector multiplied by your drift speed (transform.forward * driftSpeed) to your position. You'll need to check which direction the ship is currently moving and add that to your position.

Ex. If you're moving left transform.position += transform.left driftSpeed Time.deltaTime;

Just swap out transform.left for whatever direction you're currently moving.

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Space Game (Noob Movement Question) 0 Answers

How do I control the Max Fall Speed of the First Person Controller? 0 Answers

How to apply friction independent of framerate? 1 Answer

Artificial Gravity 2 Answers

Sphere + rigidbody + character controller 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