Set Physics velocity to 0 or disable Physics?

Get help using Construct 2

Post » Wed Jul 15, 2015 12:05 pm

Which is best. To set Physics Velocity X,Y to 0 or to disable Physics... If you want to move an object. For example the player has to spawn in a new position.

I have an object that after it has landed, I need to respawn it ( move the object ) to another location. At the moment I set Velocity to 0 and Angular velocity also to 0. After that I position my object to the new location. ... I forgot.. I also set the World.Gravity to 0 before I move my object.

Is it better to just disable Physics while I reposition my object you think?
Soulmachine @Soundcloud
B
14
S
2
G
1
Posts: 63
Reputation: 928

Post » Wed Jul 15, 2015 12:10 pm

I'm not sure what you mean..

What is the reason for changing the velocity and or disabling physics?
Is landed the same as on collision or does it only apply when the object has become stationary?
Respawn/move, I'm assuming this is done in one tick?
Would destroy the object and create a new one work?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jul 15, 2015 12:37 pm

I'll explain more. :)

I have a player that throws an object. And I'm using physics.

When the object hits a wall - it instantly has to stop. Like if you throw a knife into a wooden wall. The same has to happen when the object hits another player.
To achieve this, I set the objects velocity and angular velocity to 0 when it collides with a wall/ground or another player.
After this has happened - it's the other players turn to throw. So I reposition the object to the another player.

I do not want to destroy my object, just reposition it after it has "landed/hit something"

I'm doing a multiplayer game, so it's a bit complicated to do some things, that normally would be much easier if it just were single player.
Soulmachine @Soundcloud
B
14
S
2
G
1
Posts: 63
Reputation: 928

Post » Wed Jul 15, 2015 12:48 pm

I'm not sure why repositioning the object would be better than destroying it and spawning it at the right player, but it seems to be only one object we are talking about, so I guess it doesn't make much impact on performance in what way you do it..

I would personally choose disabling the physics behaviour on the object when not needed and reenabling it when the physics are needed again, but like I said, performance wise the difference would probably not be noticable, so I guess it's a case of whatever you like best..

You could ofcourse check the difference in performance using the debugger to make sure..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jul 15, 2015 1:54 pm

Ok. I'll consider disabling it to see what happens. It may be easier and to avoid "strange" behaviours.

Physics are a bit unpredictable and I have issues and "strange" behaviours sometimes. And it only happens after I've moved the object. The performance are no problems though.

I need things from the object, instance variables, position and such, so I cant destroy it without big problems.
Soulmachine @Soundcloud
B
14
S
2
G
1
Posts: 63
Reputation: 928

Post » Wed Jul 15, 2015 2:06 pm

Agree with LittleStain. I would disable physics in that moment but just because it's a one line action compared to set velocity, angular velocity, etc.
Lead developer at Octeto Studios

Visit our portfolio at: http://www.octetostudios.com/ :)

Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Wed Jul 15, 2015 3:27 pm

I understand. Thanks :)

I was wondering. Is it best practise to disable physics if you have to move an object (Position it) - that has the physics behaviour assigned to it?
Soulmachine @Soundcloud
B
14
S
2
G
1
Posts: 63
Reputation: 928


Return to How do I....?

Who is online

Users browsing this forum: matriax, plinkie and 1 guest