Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSmjert

Posted 10 September 2013 - 10:24 AM

I think what you need to make sure is that the total force applied is perpendicular to the velocity. From that, all you need to do is compute the projection of the heading direction onto the velocity direction and scale the force applied in the heading direction so its projection is X Newton (with the appropriate sign).

 

EDIT: The answer should be something like X/cos(velocity,heading) Newton.

So let me write this in Unity (C#) code and see if i understood it right (just testing there):

Vector3 currentVelocityDir = gameObject.rigidbody.velocity.normalized;
Vector3 currentHeadingDir = transform.forward; // This is kept up to date by Unity
float objMass = 10;
gameObject.rigidbody.AddForce(objMass * (-currentVelocityDir)); // Force to decelerate at 1 m/s^2

float cosAngle = Mathf.Cos(Vector3.Angle(currentVelocityDir, currentHeadingDir));

gameObject.rigidbody.AddForce((objMass / cosAngle) * transform.forward);

So this should be right? Because i'm not getting the correct result (the obj accelerates then suddenly lose a lot of speed, then accelerates again etc).

 

EDIT: Maybe i should add a bit more information, basicly i'm trying to simulate some assit engines that helps the spaceship to bank like an airplane but in space, but this engines have limited power. So the idea is that until the velocity direction doesn't correspond to the heading (or basicly the difference is less than some error value) i simulate an engine that decelerate on the opposite direction of the velocity and the main engines accelerating back to have constant speed, in the spaceship heading direction. Evochron uses this idea for instance (but i'm not sure about the method).


#3Smjert

Posted 10 September 2013 - 10:23 AM

I think what you need to make sure is that the total force applied is perpendicular to the velocity. From that, all you need to do is compute the projection of the heading direction onto the velocity direction and scale the force applied in the heading direction so its projection is X Newton (with the appropriate sign).

 

EDIT: The answer should be something like X/cos(velocity,heading) Newton.

So let me write this in Unity (C#) code and see if i understood it right (just testing there):

Vector3 currentVelocityDir = gameObject.rigidbody.velocity.normalized;
Vector3 currentHeadingDir = transform.forward; // This is kept up to date by Unity
float objMass = 10;
gameObject.rigidbody.AddForce(objMass * (-currentVelocityDir)); // Force to decelerate at 1 m/s^2

float cosAngle = Mathf.Cos(Vector3.Angle(currentVelocityDir, currentHeadingDir));

gameObject.rigidbody.AddForce((objMass / cosAngle) * transform.forward);

So this should be right? Because i'm not getting the correct result (the obj accelerates then suddenly lose a lot of speed, then accelerates again etc).

 

EDIT: Maybe i should add a bit more information, basicly i'm trying to simulate some assit engines that helps the spaceship to bank like an airplane but in space, but this engines have limited power. So the idea is that until the velocity direction doesn't correspond to the heading (or basicly the difference is less than some error value) i simulate an engine that decelerate on the opposite direction of the velocity and the main engines accelerating back to have constant speed, in the spaceship heading direction. Evochron uses this method for instance.


#2Smjert

Posted 10 September 2013 - 10:19 AM

I think what you need to make sure is that the total force applied is perpendicular to the velocity. From that, all you need to do is compute the projection of the heading direction onto the velocity direction and scale the force applied in the heading direction so its projection is X Newton (with the appropriate sign).

 

EDIT: The answer should be something like X/cos(velocity,heading) Newton.

So let me write this in Unity (C#) code and see if i understood it right (just testing there):

Vector3 currentVelocityDir = gameObject.rigidbody.velocity.normalized;
Vector3 currentHeadingDir = transform.forward; // This is kept up to date by Unity
float objMass = 10;
gameObject.rigidbody.AddForce(objMass * (-currentVelocityDir)); // Force to decelerate at 1 m/s^2

float cosAngle = Mathf.Cos(Vector3.Angle(currentVelocityDir, currentHeadingDir));

gameObject.rigidbody.AddForce((objMass / cosAngle) * transform.forward);

So this should be right? Because i'm not getting the correct result (the obj accelerates then suddenly lose a lot of speed, then accelerates again etc).

 

EDIT: Maybe i should add a bit more information, basicly i'm trying to simulate some assit engines that helps the spaceship to bank like an airplane but in space, but this engines have limited power (so the one that decelerate is like one on the "side", the second force added comes from the main engines, so their direction is the same of the ship heading). Evochron uses this method for instance.


#1Smjert

Posted 10 September 2013 - 10:13 AM

I think what you need to make sure is that the total force applied is perpendicular to the velocity. From that, all you need to do is compute the projection of the heading direction onto the velocity direction and scale the force applied in the heading direction so its projection is X Newton (with the appropriate sign).

 

EDIT: The answer should be something like X/cos(velocity,heading) Newton.

So let me write this in Unity (C#) code and see if i understood it right (just testing there):

Vector3 currentVelocityDir = gameObject.rigidbody.velocity.normalized;
Vector3 currentHeadingDir = transform.forward; // This is kept up to date by Unity
float objMass = 10;
gameObject.rigidbody.AddForce(objMass * (-currentVelocityDir)); // Force to decelerate at 1 m/s^2

float cosAngle = Mathf.Cos(Vector3.Angle(currentVelocityDir, currentHeadingDir));

gameObject.rigidbody.AddForce((objMass / cosAngle) * transform.forward);

So this should be right? Because i'm not getting the correct result (the obj accelerates then suddenly lose a lot of speed, then accelerates again etc)


PARTNERS