TLDR warning: if you skip to the end, yes you'll have a solution. If you read this with the intent to learn, however, you'll be better prepared for the next time you have a related issue.

Calculating the exact values to use to implement a diagonal gravity is a relatively straightforward math exercise. If you've never had to address this type of question before though, it has a notably non-obvious solution. Let's take the following hypothetical scenario to determine the exact formulas we need and create a solution for you.

We want gravity as 5 meters per second (m/s) in our scene, regardless of direction. While that's rather slow in Stencyl scale, it's a good value to use because it's a nice integer that we can do math on without getting too complicated or into extremely high values.

If we want vertical (Y) gravity or horizontal (X) gravity alone, we could simply set one or the other to 5 (or -5) to achieve this speed. As soon as we diagonal motion however, a problem presents itself in that both values need to be less than 5 m/s; but in a way that adds up to 5 m/s overall. Below is an image that uses 45 degrees to demonstrate the issue.

Imagine that the green line represents the distance traveled by an object in one second. As you know, we

*intend* that it should travel 5 meters, so therefore the green line (horizontal movement) is 5 meters distance. Looking at the red line, however, we can see that if we just give an object 5 m/s gravity both horizontally and vertically (thus the square shape), it will actually travel farther than 5 meters overall! The right half of the image, with the quarter-circle, gives you a clue that the distance (which our speed is just distance over one second of time) would be constrained within a circle from the starting point. So our problem then is to: Given an angle (the direction you wish gravity to go in) and a distance (the speed of that gravity), determine the X (horizontal gravity speed) and Y (vertical gravity speed) of a point on the circumference of that circle. Now we're getting somewhere!

So here's the real key to the question. Notice that now our green line - the correct, 5 m/s distance - is angled. Notice as well that the blue lines describe the X and Y distance to the end of the green line. The three of them form a triangle, which means that by using what we already know about the triangle, we can determine things that we don't know. In this case, that means (like we described the problem above) we can use the angle (30 degrees in this image) and length of the hypotenuse (the green line) to determine the length of the blue lines. One final picture!

So now I've broken the triangle down into individual parts. We know two of them (the angle and the length of the hypotenuse) which are yellow and green, respectively. We want the length of the blue and red line. A quick review of geometry formulas reveal the following:

1. The red line is known as the "adjacent side" because it is next to the known angle. The formula is:

Adjacent = Cosine(Angle) * Hypotenuse

or in our example...

X = Cos(30) * 5

X = .866~ * 5

X = 4.33~

So we would want our X gravity to be about 4.33 m/s in this example.

2. The blue line is known as the "opposite" side since it is opposite of the known angle. Its formula is:

Opposite = Sine(Angle) * Hypotenuse

or again in our example

Y = Sin(30) * 5

Y = .5 * 5

Y = 2.5

so our Y gravity would be 2.5 m/s in this example.

Applying both amounts of force, 4.33 and 2.5 m/s, will cause our object to travel diagonally (at 30 degrees anyway) for a distance of 5 meters in a second's time.

So after all that, here is the task for you to implement this. Create an attribute to hold the angle you want the gravity to go in, and another for the amount of force that gravity will be. Then, set both your horizontal and vertical gravity using the formula above with those two attributes inserted where needed. Any time you want to change the direction of your gravity, all you will have to do is change that angle. Obviously, if you want to increase/decrease the gravity force then you can adjust that attribute as well.

Good luck!