5
\$\begingroup\$

I have two components I'd like to connect them to each other.

  1. PhysicalComponent
    containing rigid body(position, rotation, velocity) and is holding body from physics engine.
  2. GraphicsComponent
    onscreen representation(position too, rotation too).

I'd like to sync this components, how to do it?

  1. Read position, and rotation in GraphicsComonent from Physical comopnent.
  2. Add one more component that sync them.

But problem is that I want to change on screen representation (other class such as PositionInerpolator do it, and it can work only with GraphicsComponent), and it must change physical body position. Is it a bad idea, and I must move physical body directly?

Thanks in advance.

\$\endgroup\$
1
  • \$\begingroup\$ Perhaps the graphics component should have or contain a interpolation component, its not really game logic, and assuming it is purely being used for a smoothened movement (visual) effect, why not encapsulate it. Therefore, all that needs to be passed is the position from the physical to the graphics, as to how, hopefully that will be answered. \$\endgroup\$ Dec 25, 2011 at 21:30

1 Answer 1

2
\$\begingroup\$

The way I handle it in my engine is to call a FixedUpdate() on all components when the fixed timestep physics frame ends, when the PhysicsComponent receives FixedUpdate() it will query for the rigid body position from the physics engine, if it finds a change in position since the last update it sends a message to itself saying its position has changed, and includes the new position in the message. This is a message type the RenderComponent listens for. When the RenderComponent receives the position it updates the position of the render mesh.

You're free to see the exact code for yourself if you would like, the engine is open-source, and is built on an Entity->Components hierarchy: http://quickstartengine.codeplex.com

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .