PhysicsObject.applyImpulse error :S
deybacsi

Hi guys!

I've found an interesting error, and I'm totally unable to solve it.

I've created a physics object in the editor with dynamic bodytype. If I do .applyImpulse() it works well.

If I clone the object in the code, and try .applyImpulse(), it doesn't work... Error message:

VM24315:1575 Uncaught TypeError: Cannot read property 'GetMass' of undefined
    at PhysicsObject.applyImpulse (eval at afterLoading (wade.js:2941), <anonymous>:1575:14)
    at eval (VM19044 app.js:11)
    at wade.js:3079

The code:

App = function()
{
	this.init = function()
	{
		wade.loadScene('scene1.wsc', true, function()
        {
            obj=wade.addSceneObject(wade.getSceneObject('SceneObject_0').clone(200,0));
            obj.getBehavior('PhysicsObject').applyImpulse({x: -100, y: -100});
        });
	};
};

I can't figure it out, why it works with the original object, but doesn't with a cloned one. Do you have any ideas what I'm doing wrong?

All 7 Comments
foxcode

Hi deybacsi

I'm afraid it's 23:10 where I am so I can't really debug this tonight. I will however take a look at this first thing in the morning, I'm writing myself a note now :)

We recently released a pretty big update to wade so it might not be your fault. Sorry for the wait, hopefully I can find out what's going on quickly tomorrow.

foxcode

Okay, I've had a look at this.

applyImpulse takes 3 parameters, a direction vector, a power value and an offset vector.

Check the documentation applyImpulse for further details.

However, there is also a problem with the cloning here. It seems we have to wait one update tick before we can use the newly cloned physics object. I'm not sure why this is the case, but a temporary solution is to use wade.setTimeout. I've tested the following code and it works.
 

App = function()
{
	this.init = function()
	{
		wade.loadScene('scene1.wsc', true, function()
        {
            obj=wade.addSceneObject(wade.getSceneObject('SceneObject_0').clone(200,0));
            wade.setTimeout(function()
            {
                obj.getBehavior('PhysicsObject').applyImpulse({x:1, y: 0}, 50, {x:0, y:0});
            }, 0);
        });
	};
};

You can see the only changes are the inclusion of the timeout, and the parameters in apply impulse.

{x:1, y:0} means our direction is along the positive x axis

50 is how powerful that movement should be

{x:0, y:0} is an offset vector that describes where the force should be applied from, in this case, the center of the object makes sense


This is not a great solution but hopefully it will do for now until we can take a more detailed look at this issue, thanks for bringing it up

deybacsi

Thanks for our answer, it works most of the time. :)

I must change the setTimeout value to min 50-60 in the above code, then it drops the error rarely. At 100, I've get absolutely no errors. (Sometimes it worked with 10 too :S )

I think the cloning needs some time to be finished. :/ 

As I generate more clones continuously, it becomes more tricky to guess the right number :D

I've now tried the code with the 3.6.1 online editor, it works like a charm :) It's the best & easiest solution for me, because with ~100 moving clones it's almost impossible to fine tune the right timing. :D :D :D

Gio

I have just released an update to fix this issue. If you update to 3.7.1, you should be able to do exactly what you where doing on 3.6.1.

deybacsi

Hi Gio,

It works fine with 3.7.1. :)

I checked with my phone too, and it "feels" a bit slower than 3.6.1. I wrote "feels" because I didn't benchmarked or measured anything, it's just the feeling, that it runs slower than before. :D As I read, 3.7 has a lot of improvements, so is it possible that it's slower than the previous version? 

It doesn't really matter, because this phone is a piece of s*t, a very old thingy. I was just curious. :)

Gio

Hi

3.7 is generally supposed to be faster than 3.6, and it was faster in our tests. But of course we haven't tested every possible case.

If you have a case where it's slower, I'd like to look at it, maybe we can improve something.

I would benchmark it though, perhaps on your PC as it's a lot easier than mobile.

deybacsi

Hi,

Meanwhile my phone died permanently (as I wrote it was a piece of sh*t), so there is no possibility to check if I "feelt" good this slowdown thingy...

I think any other benchmarking is unnecessary, because it was an old hardware with old software. 4 years old...

Rest in pieces, old Samsung :D

On my PC I think there will not be any measurable slowdown, because it's a relatively new hardware, and there aren't any extra hard calculations in my code.

Thanks again for your great support ;)

Post a reply
Add Attachment
Submit Reply
Login to Reply