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 Tyler 2 · Nov 06, 2010 at 06:37 AM · physics

unique physics scripting?

Hello, I have some physics scripting questions. How would I make 1 :A magnet that attracts object A 2 :A trampoline like pad that launches object an upwards at a certain velocity? -Thank you

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 Jesse Anders · Nov 06, 2010 at 07:43 PM

For a magnet, you can apply a force to the affected object at the COM and directed towards the closest point on the magnet to the affected object (or towards the magnet's center if that's suitable). For greater realism you can scale the magnitude of the force based on the distance between the object and the magnet (I don't know the exact relationship, but you should be able to find the formulae for this online).

I'm not sure what the best way to make a 'realistic' trampoline would be, but depending on what you need exactly, applying an upward impulse when the object touches the pad might be a suitable solution.

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

Answer by towerer · Nov 13, 2010 at 05:32 PM

var collidersInRange : Collider[]; var RelMagnitude ;

function FixedUpdate () {

collidersInRange = Physics.OverlapSphere(transform.position,50); for(var i : int = 2;i<collidersInRange.length;i++){

   repel(collidersInRange[i]);
 } 
 }
 else return;

}

function repel(col : Collider){

if (col.attachedRigidbody){

var trans : Transform = col.attachedRigidbody.transform;

if (trans.position.y<20){ var relativePosition : Vector3 = ( Vector3( (trans.position.x-transform.position.x+0.001), (trans.position.y-transform.position.y+0.001),0.0000001 //1/(trans.position.z-transform.position.z+0.001) ) );
RelMagnitude=relativePosition.magnitude;

Vector3.Normalize (relativePosition); col.attachedRigidbody.AddForce(1000*relativePosition/(RelMagnitude*RelMagnitude)); } } else return; }

This script repels. If you change 1000 to -1000 it will attract. If you change its value you can change the amount of push/pull. The attraction diminishes with the second power of distance as in gravity/electric forces

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

No one has followed this question yet.

Related Questions

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

OnTrigger outside the trigger and collider gamobject 1 Answer

i need help with my skateboard physics 0 Answers

Dragging ONE rigidbody 1 Answer

How can I play audio while a non player controlled object is moving and stops playing when object stands still? 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