Physics World Gravity not exposed in expressions?

0 favourites
  • 3 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Can someone confirm that you cannot access the physics object's world gravity parameter via expressions? For example, you can set the gravity using the appropriate event, but cannot get the gravity value using object.physics.WorldGravity or similar.

    If not can you access it via JS?

  • You’re correct, there isn’t an expression for the gravity. It’s by default 10, but I usually use a variable to store the value and set the gravity with that.

    Sometimes the manual lists the exposed js values/functions for behaviors, but if not I try to use console.log with an object and then open up the browser debugger and browse the members, sub-members and so forth.

    Basically what you’re after is to

    1. Find an instance of an object with physics

    2. Access the physics behavior instance.

    3. That should have a reference to the box2d world. If the behavior instance doesn’t have it then you may find it in the behavior instance’s type which you should be able to find a reference.

    4. Once you get the the box2d world you should be able to find the gravity vector.

    Anyways that’s the rough process I use to try to find stuff in js.

    I’m not on my computer but if you used the browser execute js action you may be able to access the gravity with something like:

    this.runtime.getInstanceByUid(3).behaviors[0].type.world.gravity

    The names of everything are probably incorrect so I’d have to check along the way with console.log to see what the correct names are. That and it may be a slightly different path.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks ROJO. Yes, easy to work around but I just found it odd that it is not exposed. Will have a poke around with the logger and see if I can find it in JS.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)