Skip to content

Commit

Permalink
Added rotateToVelocity to Arcade Physics component. Issue #179
Browse files Browse the repository at this point in the history
  • Loading branch information
zfreiberg committed Feb 16, 2015
1 parent d772d25 commit b7710ab
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
7 changes: 7 additions & 0 deletions build/kiwi.d.ts
Expand Up @@ -6137,6 +6137,13 @@ declare module Kiwi.Components {
*/
parent: Kiwi.Entity;
/**
* Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
* @method rotateToVelocity
* @return { Number }
* @public
*/
rotateToVelocity(): number;
/**
* A static method for seperating two normal GameObjects on both the X and Y Axis's.
* Both objects need to have both an ArcadePhysics Component and a Box component in order for the separate process to succeed.
* This method is not recommended to be directly used but instead use a 'collide/overlaps' method instead.
Expand Down
11 changes: 11 additions & 0 deletions build/kiwi.js
Expand Up @@ -8658,6 +8658,17 @@ var Kiwi;
this._callbackFunction = callbackFunction;
this._callbackContext = callbackContext;
};
/**
* Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
* @method rotateToVelocity
* @return { Number }
* @public
*/
ArcadePhysics.prototype.rotateToVelocity = function () {
var result = Math.atan2(this.velocity.y, this.velocity.x);
this.transform.rotation = result;
return result;
};
/*
*---------------
* Seperation Code
Expand Down
16 changes: 8 additions & 8 deletions build/kiwi.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/components/ArcadePhysics.ts
Expand Up @@ -326,6 +326,22 @@ module Kiwi.Components {
*/
public parent: Kiwi.Entity;

/**
* Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
* @method rotateToVelocity
* @return { Number }
* @public
*/
public rotateToVelocity (): number {

var result: number = Math.atan2( this.velocity.y, this.velocity.x );

this.transform.rotation = result;

return result;

}


/*
*---------------
Expand Down
11 changes: 11 additions & 0 deletions templateGame/lib/kiwi.js
Expand Up @@ -8658,6 +8658,17 @@ var Kiwi;
this._callbackFunction = callbackFunction;
this._callbackContext = callbackContext;
};
/**
* Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
* @method rotateToVelocity
* @return { Number }
* @public
*/
ArcadePhysics.prototype.rotateToVelocity = function () {
var result = Math.atan2(this.velocity.y, this.velocity.x);
this.transform.rotation = result;
return result;
};
/*
*---------------
* Seperation Code
Expand Down

0 comments on commit b7710ab

Please sign in to comment.