javascriptjqueryconsole.logbox2dweb

Console.log object velocity with box2d


I'm trying to console.log the velocity of an object with box2dweb It should be possible to get velocity with following method GetLinearVelocity() but I'm not sure how to do? I've tried the following ways:

    var heroMove = GetLinearVelocity().hero;
    console.log('heroMove');

and

var heroMove = GetLinearVelocity('hero');
console.log('heroMove');

In console I get the message:

ReferenceError: GetLinearVelocity is not defined

It's probably an easy answer, but seems like there is no doc for jquery.box2d and I can't see whats wrong?


Solution

  • I found the solution myself. It looks like this:

            var heroVelX = game.currentHero.GetLinearVelocity().x;
            var heroVelY = game.currentHero.GetLinearVelocity().y;
            console.log("X =", heroVelX + "Y =", heroVelY);
    

    The value of GeltLinearVelocity() is a vector and not a number and therefor has to be specified as x and y. Hope someone else can use it.