Hey. I'm working on a game called NET, a 2D platformer which is on the surfaces of 3D objects, and in order to make it work I need to use a modifiable gravity. I have a simple 2D controller already created for a deadline, which I think I will apply the principles of to this project to allow the programmer to select the four cardinal gravity directions - up, down, left, or right - which can be used as a baseline for future revisions. But before I go ahead, I'd like to pitch my idea and see if it seems viable. Here's what I did in the original controller:
The original controller contained a few key elements. It was fed a gravity constant, a gravity direction, and using the direction, it referenced two Func<Vector2, Vector2>
fields: VecRotate
, which rotates from down to the set gravity direction, and InvVecRotate
, which rotates from the set gravity direction to downward.
Any time a Vector2 needed to be referenced in the script, it would be preceded by one of these two Func
s. For example, the control code went like this:
void Update() {
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
Vector2 modified = VecRotate(input); // Turn the input so that it matches the gravity, ex. if gravity faces right, the horizontal becomes the vertical, etc
rigid.velocity = modified;
}
It's a bit simplified, but that's effectively the idea - and that's the principle I plan to apply to the four-direction gravity version of the PC2D. And more skilled programmers, in future builds, can use the same framework; instead of four cardinal directions, just have the VecRotate and InvVecRotate properties refer to more general Funcs for the angle.
Thoughts?