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, 2011 at 06:02 PM

Muzz 1 gravatar image

Muzz 1
653 152 115 132

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

3 answers: sort voted first

You can use joints. Try it!

more ▼

answered Jan 13, 2011 at 06:20 PM

Borgo gravatar image

Borgo
1.1k 23 24 40

OO fancy. Yes, thats prolly a better idea

Jan 13, 2011 at 06:22 PM Bob5602

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

Jan 13, 2011 at 06:39 PM Muzz 1

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

Jan 13, 2011 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, 2011 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, 2011 at 06:12 PM

Bob5602 gravatar image

Bob5602
603 40 33 50

(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, 2011 at 09:31 PM

efge gravatar image

efge
5.3k 20 26 57

(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:

x9227
x6257
x3181
x2
x2

asked: Jan 13, 2011 at 06:02 PM

Seen: 2182 times

Last Updated: Jan 13, 2011 at 06:02 PM