x


Magnetism in javascript

I'm entering a science competition, and need to model magnetism in Unity. Is there a way of writing this in Javascript?

more ▼

asked Jan 13 '11 at 06:02 PM

Muzz 1 gravatar image

Muzz 1
593 55 60 72

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You can use joints. Try it!

more ▼

answered Jan 13 '11 at 06:20 PM

Borgo gravatar image

Borgo
1k 10 13 25

OO fancy. Yes, thats prolly a better idea

Jan 13 '11 at 06:22 PM Bob5602

Well, I want it to be invisible, so it looks like magnetism.

Jan 13 '11 at 06:39 PM Muzz 1

I've never unity before this... sorry if this is ridiculously noobish.

Jan 13 '11 at 06:40 PM Muzz 1

The joints are invisible and looks like magnetism, depends of type.

http://unity3d.com/support/documentation/Components/comp-DynamicsGroup.html

Jan 13 '11 at 06:48 PM Borgo
(comments are locked)
10|3000 characters needed characters left

What I would do..

Make 2 game objects, then put some kind of attraction force between them. Something like moving one object toward the other and vice versa, so they appear "attracted." Then make the amount of movement is inversely proportional to the distance (Vector3.Distance) between the two objects. Then, the closer they get, the faster they go!

more ▼

answered Jan 13 '11 at 06:12 PM

Bob5602 gravatar image

Bob5602
588 15 17 29

(comments are locked)
10|3000 characters needed characters left

I would suggest to also use Rigidbody.AddForce:

Attach a SphereCollider with a wider radius set as Trigger and a RigidBody to your GameObjects.
Use OnTriggerEnter to start Rigidbody.AddForce in the direction of the other object/collider.
Increase/decrease the added force depending on distance.
(When both GameObjects collide you could use a FixedJoint or parenting.)

more ▼

answered Mar 03 '11 at 09:31 PM

efge gravatar image

efge
5.2k 8 15 41

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7780
x5377
x2722
x2
x2

asked: Jan 13 '11 at 06:02 PM

Seen: 1824 times

Last Updated: Jan 13 '11 at 06:02 PM