Hallo,
I have a very simple question, but I do not get it running, as I want:
I simply want to move an Entity by a program, let's say a platform, that goes up and down automatically. When I use the move or moveTo function on that entity, the physic seems not to work properly. For example, when something hits the platform it is not moved up or down correctly. The I tried to simulate the moving by using the velocity function. That worked, but it is not as correct, as using move.
So how do I move entity objects correctly?
Moving Physic-Objects
Re: Moving Physic-Objects
One way to do it is to set the linearVelocity based on how much you've moved it. For example, before you move, store the entity's internalCenterPosition. Move the object and get the difference between the new and old positions. Divide this vector by the timestep (space.simulationSettings.timeStep) and you'll have a velocity that you can set the entity's internalLinearVelocity to.
This isn't completely accurate since it's always operating on the last frame's information, but it's significantly better than having no velocity input at all.
You could also do the reverse and compute the exact velocity necessary to make a move in the next frame that takes the platform to the desired location. This might be a little trickier to fit into your system depending on how it is set up, but it is an option.
This isn't completely accurate since it's always operating on the last frame's information, but it's significantly better than having no velocity input at all.
You could also do the reverse and compute the exact velocity necessary to make a move in the next frame that takes the platform to the desired location. This might be a little trickier to fit into your system depending on how it is set up, but it is an option.