Skip to content

Commit d7af904

Browse files
committed
Added Matter velocity, angularVelocity and force methods
1 parent 478d698 commit d7af904

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Version 3.18.0 - Raphtalia - in dev
44

5+
### New Features
6+
7+
* `Matter.Factory.velocity` is a new method that allows you to set the velocity on a Matter Body directly.
8+
* `Matter.Factory.angularVelocity` is a new method that allows you to set the angular velocity on a Matter Body directly.
9+
* `Matter.Factory.force` is a new method that allows you to apply a force from a world position on a Matter Body directly.
10+
511
### Updates
612

713
* `Zones` will now use the new `customHitArea` property introduced in 3.17 to avoid their hit areas from being resized if you specified your own custom hit area (thanks @rexrainbow)

src/physics/matter-js/Factory.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var Bodies = require('./lib/factory/Bodies');
8+
var Body = require('./lib/body/Body');
89
var Class = require('../../utils/Class');
910
var Composites = require('./lib/factory/Composites');
1011
var Constraint = require('./lib/constraint/Constraint');
@@ -607,6 +608,65 @@ var Factory = new Class({
607608
return MatterGameObject(this.world, gameObject, options);
608609
},
609610

611+
/**
612+
* Instantly sets the linear velocity of the given body. Position, angle, force etc. are unchanged.
613+
*
614+
* See also `force`.
615+
*
616+
* @method Phaser.Physics.Matter.Factory#velocity
617+
* @since 3.18.0
618+
*
619+
* @param {MatterJS.Body} body - The Matter Body to set the velocity on.
620+
* @param {Phaser.Types.Math.Vector2Like} velocity - The velocity to set. An object with public `x` and `y` components.
621+
*
622+
* @return {MatterJS.Body} The Matter body.
623+
*/
624+
velocity: function (body, velocity)
625+
{
626+
Body.setVelocity(body, velocity);
627+
628+
return body;
629+
},
630+
631+
/**
632+
* Instantly sets the angular velocity of the given body. Position, angle, force etc. are unchanged.
633+
*
634+
* See also `force`.
635+
*
636+
* @method Phaser.Physics.Matter.Factory#angularVelocity
637+
* @since 3.18.0
638+
*
639+
* @param {MatterJS.Body} body - The Matter Body to set the velocity on.
640+
* @param {number} velocity - The angular velocity to set.
641+
*
642+
* @return {MatterJS.Body} The Matter body.
643+
*/
644+
angularVelocity: function (body, velocity)
645+
{
646+
Body.setAngularVelocity(body, velocity);
647+
648+
return body;
649+
},
650+
651+
/**
652+
* Applies a force to a body from a given world-space position, including resulting torque.
653+
*
654+
* @method Phaser.Physics.Matter.Factory#force
655+
* @since 3.18.0
656+
*
657+
* @param {MatterJS.Body} body - The Matter Body to set the force on.
658+
* @param {Phaser.Types.Math.Vector2Like} position - The world position to apply the force from. An object with public `x` and `y` components.
659+
* @param {Phaser.Types.Math.Vector2Like} force - The force to set. An object with public `x` and `y` components.
660+
*
661+
* @return {MatterJS.Body} The Matter body.
662+
*/
663+
force: function (body, position, force)
664+
{
665+
Body.applyForce(body, position, force);
666+
667+
return body;
668+
},
669+
610670
/**
611671
* Destroys this Factory.
612672
*

0 commit comments

Comments
 (0)