0 Favourites

Physics object horizontal axis?

  • Hi guys

    I've been playing around with physics and its fun, but I'm having trouble with something that seems like it should be pretty simple.

    Is there a way to move a physics object along horizontal axis only (using a joint possibly). Basically I'm trying to get an object to slide from left to right and back again.

    Any ideas would be awesome

    Thank you!

  • Things 'slide' when on a 'ground'. Ground = an immovable object.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Hi 99Instances2Go

    Thank you for the suggestion, I've been playing around with sliding it along a ground object, but I was wondering whether there is a way to have a sort of physics 'motor' or 'joint' that will limit to only horizontal movement?

  • Set gravity to 'zero', be aware that if you do that for 1 object, you do it for all. There is no concept as a 'personal' gravity in c2.

    That is why you have to do this with an action, so you can not set gravity to zero by accident. The action is under (any) object with physics attached, under Physics > global settings > Set world gravity.

    Now, just 'Apply force towards position' with x = object.X + 200 and Y = object.Y

    Or. 'Apply force at angle' with angle = zero or 180

    Be aware that a force is applied 'every tick' and an impulse is applied 'only once'.

    Now you have a horizontal floating object.

    If you need gravity. Then you have to counter the force of gravity. Gravity is applied 'every moment', under a 90 degrees angle. If keeping the defaults it is 10 m/s^2. That is just close to Earths gravity 9.80665 m/s^2.

    Just as in the real world, to fly we need to apply a force, and in the opposite direction of gravity.

    Just as in the real world, objects fall at the same speed, no matter its mass.

    But, when we apply a force, the effect of that force depends on the mass of the object. How more mass the object as, how more force we need to move it the same distance.

    In the real world, the force that we need to apply is just its weight. Weight = Mass * Gravity.

    To do that in C2 we meet 2 problems. Its mass calculation has a conversion problem build in. And physics divides time in pieces of length 1/60 (in its default state), not in length dt (1 tick).

    So lets make this story shorter, save you the math, and kill time and conversion problems.

    'Apply force at angle' with ....

    angle = 270

    Force = (Sprite.Physics.Mass ) * (1/60) * (gravity + (gravity/5))

    gravity = the number that you used with the action 'Set world gravity'

  • Hi 99Instances2Go

    Thank you for the detailed reply

    I will play with around with your suggestions and see what I can come up with.

    I really appreciate you help!

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