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
3
Question by DanjelRicci · Jan 27, 2010 at 07:13 PM · physicsraycastvehicle

Creating a magnetic vehicle (like F-Zero)

I would like to create a game similar to F-Zero. In order to do this, I need my starship to "stick" to the track (hovering just a bit), even if the track is upside-down or twisted. I also need to constrain the physics and the controls only over its local X and Z axis, because the vertical one is not needed.

I was thinking to use a Raycast collider that goes down the Y axis of the ship to inherit the track angulation, but my scripting abilities are really poor right now. Can anyone help me with a sample code, please? 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

1 Reply

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

Answer by duck · Jan 27, 2010 at 09:17 PM

Here's a very simple version. First, set your vehicle's rigidbody to not be affected by gravity (it's a checkbox in the inspector).

Next, in your script, you'd probably want something like this in your FixedUpdate() which computes the ideal hover position, based on where the ray hits the surface. Now you have your ideal hover position, you need to apply a force to move your ship towards it. The script would probably look something like this (sorry, don't have time to test now):

var hit : RaycastHit; if (Physics.Raycast (transform.position, -transform.up, hit, 100.0)) { idealPosition = transform.position + ((hoverHeight-hit.distance) * transform.up); }

var pull : Vector3 = (idealPosition - transform.position); rigidbody.AddForce( pull );

Comment
Add comment · Show 7 · 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 DanjelRicci · Jan 27, 2010 at 10:48 PM 0
Share

Thanks for the reply! I tested it, but I got this errors:

1 - "Assets/Raycast Collider.js(6,40): BCE0051: Operator '-' cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'float'."

2 - "Assets/Raycast Collider.js(9,49): BCE0019: 'Position' is not a member of 'UnityEngine.Transform'. Did you mean 'position' ?"

avatar image duck ♦♦ · Jan 28, 2010 at 07:27 AM 0
Share

tweaked it a bit. Yes I meant "position" ins$$anonymous$$d of "Position"! still not in front of Unity so I can't test again, but see how it goes.

avatar image DanjelRicci · Feb 01, 2010 at 10:23 AM 0
Share

Ok, thanks! I'm going to try it today. Precisely, I need to allign the vehicle to the triangle detected by the Raycast.

avatar image DanjelRicci · Feb 01, 2010 at 07:37 PM 0
Share

I tried the script: unfortunately it doesn't help. :( The ship correctly hovers on the track at the right height, but it doesn't stick to it: where the track is wavy, the ship jumps away!

avatar image duck ♦♦ · Feb 01, 2010 at 08:16 PM 0
Share

have you tried increasing the amount of force applied? eg: rigidbody.AddForce( pull * someFactor );

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

No one has followed this question yet.

Related Questions

Raycast Car-Vehicle Physics 1 Answer

How do i make my Raycast Car not slip at all? 0 Answers

Raycast align with ground normal 2 Answers

Line of Sight with Physics.Linedraw or Physics.Raycast Unreliable? 1 Answer

Hovercraft Physics Problems 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