Hi!
I'm creating something similar to planet gravity. I have a body and I'm calculating vector from it's position to center of the screen, then I'm applying force to my body giving that vector. It's working, my body moves towards center of the screen. Now I want it to move around so I added second force that is perpendicular to previous calculated vector. And it's working too.
What I want to do is to move my body at constant speed, always. Right now it simulates physics so it accelerates when it's moving towards center of the screen and decelerating when it's moving in other direction. I want it to move with constant speed towards center of my screen, without acceleration.
My code looks like this (pseudocode based on C++/Java):
Any suggestions? 🙂
I'm creating something similar to planet gravity. I have a body and I'm calculating vector from it's position to center of the screen, then I'm applying force to my body giving that vector. It's working, my body moves towards center of the screen. Now I want it to move around so I added second force that is perpendicular to previous calculated vector. And it's working too.
What I want to do is to move my body at constant speed, always. Right now it simulates physics so it accelerates when it's moving towards center of the screen and decelerating when it's moving in other direction. I want it to move with constant speed towards center of my screen, without acceleration.
My code looks like this (pseudocode based on C++/Java):
Code: Select all
vec2 bodyPosition= body.getPosition();
vec2 screenCenter = new vec2(ScreenWidth/2, ScreenHeight/2);
vec2 vectorToCenter = screenCenter - bodyPosition;
vec2 perpendicularVector = new vec2(screenCenter.x, -screenCenter.y);
body.applyForceToCenter(perpendicularVector); // move body around
body.applyForce(vectorToCenter, bodyPosition); //move body towards center of the screen
Any suggestions? 🙂