How do I change mass during the game?

dallasrosin

  • Posts: 1
I have a actor that need to change the mass during the game.  I see how I can set the physics during setup, but once the game is started, I can't figure out how to make the computer change it.

If I knew the variable that was used maybe I could adjust it, but I looked everywhere that I could think of, and couldn't find the mass variable.

Any ideas?

Thanks in advance,
-Dallas

Alexin

  • *
  • Posts: 3127
You need some code. I don't know about iOS but here is the code for AS3.

Code: [Select]
import Box2DAS.Collision.Shapes.b2MassData;
b2MassData massData = new b2MassData();
actor.body.GetMassData(massData);
massData.mass = 10.0;
actor.body.SetMassData(massData);

Replace "10.0" by the mass you desire to set. I haven't tested this but it shouldn't too far off.
"Find the fun"
alexin@stencyl.com

unatron

  • Posts: 9
Thanks for posting this Alexin! I tried using this code but am getting syntax errors. I wish I knew how to fix them, but I am 100% unfamiliar with actionscript. Can you/anyone else help?

Behavior: Design_61_61_GrowandShrink at line 39
Syntax error: expected a definition keyword (such as function) after attribute b2MassData, not massData.
b2MassData massData = new b2MassData();

Behavior: Design_61_61_GrowandShrink at line 39
Syntax error: expecting rightbrace before semicolon.
b2MassData massData = new b2MassData();

unatron

  • Posts: 9
Got it working! Well, someone else got it working for me.

import Box2DAS.Collision.Shapes.b2MassData;
var massData:b2MassData = new b2MassData();
actor.body.GetMassData(massData);
massData.mass = 10.0;
actor.body.SetMassData(massData);