Jump to content

  • Log In with Google      Sign In   
  • Create Account


Better way of doing constraints


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 CryoGenesis   Members   -  Reputation: 495

Like
0Likes
Like

Posted 08 September 2012 - 02:55 PM

Hey, I'm making my first proper 2D physics engine (I guess a kind of right of passage).

I've started by doing vector to vector constraints.
It works at the moment but it uses a kind of Master/Slave thing where one vector can move and move the other but when the slave vector moves it doesn't move the master (like a pendulum).
Here's the code:

//Finds out the angle between the vectors
angle = 90 + a.getAngle(b);

//Positions accordingly
b.x = a.x + distance*Math.sin(Math.toRadians(-angle));
b.y = a.y + distance*Math.cos(Math.toRadians(-angle));

Anyway of making it so they move each other?

Sponsor:

#2 wildbunny   Members   -  Reputation: 550

Like
1Likes
Like

Posted 10 September 2012 - 11:19 AM

Hi there,

Sure, you need to design your constraint so it works in 'relative space' and pushes on object A while pulling on B.

I wrote just the article which should help you out with understanding how to design a constraint:

http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/

It starts off dealing with simple concepts and builds up to designing a constraint :)

Hope that helps!

Cheers, Paul.

#3 CryoGenesis   Members   -  Reputation: 495

Like
0Likes
Like

Posted 11 September 2012 - 11:29 AM

Thanks! took so long to get an answer. +1rep:)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS