Physics object horizontal axis?

Discussion and feedback on Construct 2

Post » Thu Jul 20, 2017 9:10 am

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!
B
47
S
23
G
9
Posts: 151
Reputation: 9,253

Post » Thu Jul 20, 2017 11:28 pm

Things 'slide' when on a 'ground'. Ground = an immovable object.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jul 21, 2017 3:01 am

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?
B
47
S
23
G
9
Posts: 151
Reputation: 9,253

Post » Fri Jul 21, 2017 3:14 pm

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'
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jul 22, 2017 4:32 am

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!
B
47
S
23
G
9
Posts: 151
Reputation: 9,253


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 12 guests