How “AWPRigidBody.applyCentralForce()” affects “AWPRigidBody.front”?

Software: Away3D 4.x

erroneous seth, Newbie
Posted: 26 October 2011 03:25 PM   Total Posts: 28

Hello to everyone,

I try to move a Sphere on a Plane. I use the mouse’s “x offset” from the center of the screen to rotate the Sphere. Then, when the user “presses the ctrl button and clicks” a constant force is applied to the Sphere.

The code used is the following:

private function onMouseClick(event MouseEvent) : void {
    if (
("force.x: " force.", force.y: " force.", force.z: " force.z);

(BALL_FORCE is a Number declared as “private static const”)

And the traces received are:

force.x: 0, force.y: 0, force.z: -700

force.x: 0, force.y: 0, force.z: -700

force.x: 0, force.y: -41.85575713419593, force.z: 698.7475192047004

force.x: 0, force.y: 699.308698847882, force.z: 31.10214969551242

force.x: 0, force.y: 698.5301337461049, force.z: 45.339301369218916

force.x: 0, force.y: 694.9358876001116, force.z: 84.0482725904877

As you can see, after 2 or 3 loops the “front” vector changes direction as far as its height (y-axis) is concerned while the “force” applied remains the same (or at least, I think it does).

So, I would like to ask how does the “applyCentralForce” method affects the “front” property of an AWPRigidBody?

Thank you very much.


John Brookes, Moderator
Posted: 26 October 2011 05:27 PM   Total Posts: 732   [ # 1 ]

The sphere rolls so the forward vector changes.


erroneous seth, Newbie
Posted: 28 October 2011 12:58 PM   Total Posts: 28   [ # 2 ]

Thank you very much for your answer.

I thought so, too.

As I understand, I will have to manually calculate a “front vector” without taking into account the current rotation of the “mesh”.

I will post “source code” and results.


John Brookes, Moderator
Posted: 28 October 2011 01:38 PM   Total Posts: 732   [ # 3 ]

Use torque to roll.

This uses Torque impulse and moves a sphere with keys based on where a camera orbiting the origin is looking

var cmP:Vector3D camera.position.clone();
cmP.scaleBy((sphereRollForce 60));//60=fps
if (keyForward)
myRigidBody.applyTorqueImpulse(new Vector3D(cmP.* -10cmP.x));
if (
myRigidBody.applyTorqueImpulse(new Vector3D(cmP.z0cmP.* -1));
if (
myRigidBody.applyTorqueImpulse(new Vector3D(cmP.* -10cmP.* -1));
if (
myRigidBody.applyTorqueImpulse(new Vector3D(cmP.x0cmP.z)); 

erroneous seth, Newbie
Posted: 01 November 2011 03:55 AM   Total Posts: 28   [ # 4 ]

JohnBrookes, thank you very much for your answer.

I found a way to deal with the changing “front vector”. However, my solution still uses the “applyCentralForce” method. I don’t know if it is more suitable than using torque, as you suggest.

Below, I explain the solution I came up with.

Since, the only thing given is the new force vector’s angle relative to the sphere’s local “z-axis”, the following constitutes the calculation of the new force vector:

1. decomposition of the new force vector to its “x & z” components
2. addition of the two components to produce the new force’s vector

The code used:

private function updateForce() : void {
/* Angle between sphere "z-axis" and new force. */
var theta:Number _forceAngle*MathConsts.DEGREES_TO_RADIANS;
/* Decompose new force's vector to its "z" and "x" component. */   
var xFactorLength:Number Math.sin(theta);
zFactorLength:Number Math.cos(theta);
/* Compose the new force from its components. */
_force = new Vector3D(xFactorLength0zFactorLength);

Thank you for your answers.



Away3D Forum

Member Login