Fix rigid body callback

This commit is contained in:
Lubos Lenco 2017-04-20 11:13:33 +02:00
parent 8fe5f6b9c1
commit b21e0fe099
2 changed files with 6 additions and 4 deletions

View file

@ -23,6 +23,8 @@ class GunController extends Trait {
public function new(projectileRef:String, firePointRef:String) {
super();
this.projectileRef = projectileRef;
notifyOnInit(function() {
firePoint = object.getChild(firePointRef).transform;
@ -41,10 +43,9 @@ class GunController extends Trait {
o.transform.loc.z = firePoint.absz();
// Apply force
var rb:RigidBody = o.getTrait(RigidBody);
rb.notifyOnReady(function() {
var look = object.transform.look().normalize();
rb.setLinearVelocity(look.x * fireStrength, look.y * fireStrength, look.z * fireStrength);
});
rb.syncTransform();
var look = object.transform.look().normalize();
rb.setLinearVelocity(look.x * fireStrength, look.y * fireStrength, look.z * fireStrength);
// Remove projectile after a period of time
kha.Scheduler.addTimeTask(function() {
o.remove();

View file

@ -60,6 +60,7 @@ class RigidBody extends Trait {
public function notifyOnReady(f:Void->Void) {
onReady = f;
if (ready) onReady();
}
public function init() {