- Home /
Are point effectors (2D) simulated when you use the physicsscene2d simulate function?
I'm trying to make a 2D game where you can shoot missiles at planets but the planets have 2d point effectors so if the missile comes within the range of the planet it gets attracted towards it. To aim I'm trying to predict the trajectory of the missile using a physics scene simulation mostly following the video https://www.youtube.com/watch?v=4VUmhuhkELk . The creation of the physics scene:
CreateSceneParameters parameters = new CreateSceneParameters(LocalPhysicsMode.Physics2D);
predictionScene = SceneManager.CreateScene("Prediction", parameters);
predictionPhysicsScene = predictionScene.GetPhysicsScene2D();
Physics2D.autoSimulation = false;
currentScene = SceneManager.GetActiveScene();
currentPhysicsScene = currentScene.GetPhysicsScene2D();
I manually simulate the current physics scene in the fixedupdate.
Then I move a dummy missile and dummy planets (same as the regular missiles and planets but without sprites) using the MoveGameObjectToScene function
And finally to simulate the missiles:
LineRenderer lineRenderer = currentDummyMissile.GetComponent<LineRenderer>();
lineRenderer.positionCount = numIterations;
dummyRB.AddForce(Force, ForceMode2D.Impulse); //Launching the missile (this works)
for (int i=0; i<numIterations; i++) {
predictionPhysicsScene.Simulate(Time.fixedDeltaTime);
lineRenderer.SetPosition(i, currentDummyMissile.transform.position);
}
For some reason though the point effectors don't seem to have an effect on the physics simulated dummy missile. Are they not simulated when you call the Simulate function? If not is there a better way to predict the trajectory of the missile? I have also tried manually creating the effect of the point effector by scripting it out and adding force inside the OnTriggerStay2D function but that also has no effect.
Answer by Advaith23 · Feb 23, 2021 at 10:26 AM
Okay it turns out the Point Effectors are simulated. I think the issue was that my missile was moving too fast for the point effectors to have any effect. I reduced the impulse force and increased the numIterations and the trajectory was simulated correctly.
Your answer
Follow this Question
Related Questions
What is the best way to implement physic simulation prediction for AI in Unity? 1 Answer
Is there a way to create water like behavior. 0 Answers
Break 2d joint? 1 Answer
Physics2D simulation is not taking into acount the material's Friction 1 Answer
elastic collision simulation loses 400 kgm/s momentum in a few hours 1 Answer