• entry
1
• comment
1
• views
573

# Proof of Concept

1161 views

Greetings everyone!

I finally managed to put together complete system that will be used as a backbone of my new game. The game itself is supposed to be a mix of Kerbal Space Program and Space Engineers in 2d, maybe with some added influences from other games. I'll get back to this later, when gameplay is more fleshed out. Right now what the game needs is: orbital physics of planetary system, large deformable terrains with rigid body simulation and transitions between those two.

tl;dr; There is a video.

#### Orbital physics

This part was relatively easy. I choose simulated n-body system over fixed orbits with patched conic approximation. It's simple to write and supports all phenomena like Lagrange points. My system uses Verlet integration with fixed time step (64s) for planets and adaptive time step for small entities (artificial satellites, asteroids). The only drawback here is that plotting trajectories requires to know positions of all planets ahead of time, so it's best to evaluate whole system many steps to the future and just playback current position from history. (You can see these in video when debug drawing is enabled)

#### Planetary physics

I modeled planet's surface as linear space located around planet radius, with wrapping around when traveling sideways. Since I want my planets big (not real live big, not even KSP big, but still), each one is split into spaces that span around 4km.

Those spaces are all linear and centered around origin. Rigid bodies can move from one to another, can have joints across spaces, but will never collide or interact in any way.

Of course the problem is when some body wants to leave one space and enter another. We could simply teleport whole rigid body, but it would miss some collisions.

My solution is to clone whole body at new location and link them with teleport joint. It's similar to fixed joint, but maintains relative offset. (don't forget to split mass in half between two bodies)

In order for this to work, you need two bounding rectangles: tight and fat. When tight intersects space boundary clone body (2). Destroy cloned body only if fat stops intersecting boundary (4).

For all this to work I made some changes to Box2D library, you can find my fork on github.

#### Stitching it together

Moving from planet surface space to orbital space is using simple teleportation with conversion from local space coordinates to global orbital one. I sill have some quirks to iron out, but hey, you can fly to the moon!

## 1 Comment

Wow, such space much love!
Cool game idea, keep at it .
I've been thinking about this wrapping space for planets and the physics of it for a mining game prototype. Never really throw real work effort at it but you cleared the whole idea up with this entry, thanks !

## Create an account

Register a new account

• ### Similar Content

• By mtjscott
Hey, so i've created a disk in unity (2D mobile) that will be shot forward if you drag it back and the further you drag it from the start point the more force will be applied to the impulse similar to the 8ball pool drag to shoot mechanic on miniclip. However, when I applied a script that allows the main camera to follow the ball it broke the mechanic since the balls position is calculated through the camera in world space. So I created a bool that locks the camera in place until the ball is released so the calculation would happen before the camera starts to move. This works however the ball now rubber bands back and forwards close to the start position.

If anything needs more explaining then i'd be glad to do so. I've only been coding for about a week so you'll have to bare with me. Any help is appreciated. Thank you very much.

Here's What happens:
(screencap gif of the game viewer)

Here is the shoot script:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Shoot : MonoBehaviour { [SerializeField] GameObject Disc; [SerializeField] float multiplier; Vector3 initPos; private Rigidbody2D rb; public static bool ballIsReleased = false; bool recordingDistanceDragged = false; private void Start() { rb = gameObject.GetComponent<Rigidbody2D>(); initPos = transform.position; } void OnMouseDrag() { recordingDistanceDragged = true; if(recordingDistanceDragged == true) { transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)); } else { transform.position = initPos; } } void OnMouseUp() { ballIsReleased = true; } private void FixedUpdate() { if(ballIsReleased == true) { rb.AddForce((initPos - transform.position) * multiplier, ForceMode2D.Impulse); Debug.Log("ball is released"); recordingDistanceDragged = false; } else { ballIsReleased = false; } } }
Here is the camera follow script:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFollow : MonoBehaviour { private Vector2 velocity; public float smoothTimeY; public float smoothTimeX; public GameObject player; private void Start() { player = GameObject.FindGameObjectWithTag("Player"); } private void FixedUpdate() { if (Shoot.ballIsReleased == true) { Debug.Log("camera can move"); float posX = Mathf.SmoothDamp(transform.position.x, player.transform.position.x, ref velocity.x, smoothTimeX); float posY = Mathf.SmoothDamp(transform.position.y, player.transform.position.y, ref velocity.y, smoothTimeY); transform.position = new Vector3(posX, posY, transform.position.z); } } }

• Welcome everyone, this is the last video on section and end of our Terminal Hacker game. In this video we will learn to create random number.
And from our next section we will create 3d game
We will create CUBE RACE for our lesson.

• The massively popular memes "Bongo Cat" has been made into a smartphone game!

Welcome to Bongo Cat DUELS! Wild West is waiting for you. Fight vicious enemies, upgrade cat skills and buy new guns.

FEATURES:

-Participate in duels;

-Get money and experience for winning;

-Open new duels;

• By Tanzan
Hello  all,
I just finished my first Android game and published it on Google play...
I know its not the next red dead redemption2 but it would be nice to have some comments/feedback on it if its worth it to go on with a release 2.0. or move on to the next game? (red dead redemption 3  )
Anyway thx for your reading time and i hope on some nice reviews!
Regards,

Tanzan

• By Sultown
Good evening.
Before I get to my question, I'd like to clarify that this is in a 2D (2.5D) view with pixel graphics. While making mockups, a question on map design came to me. If I were to draw an entire section of a map, including stairs, buildings, etc. would I be able to set constraints so that a character could move realistically on one asset (the room, I guess), Instead of having to place each and every tile for every corner, or variation in design, or every stair?
I feel like this would be much easier when it comes to very intricate room designs that would be much cleaner and aesthetically pleasing if I could just put wall barriers (native to my engine) where the player can not go.
Let me know if this needs clarification or if this is in the wrong subforum.
Thanks.
×