Getting Mathematica to solve a system of two second order nonlinear ordinary differential equations

I tried solving a system of two second order nonlinear ordinary differential equations using the DSolve command. First, I tried like this:

eqns = {A''[x] == 2/B[x]*A'[x]*B'[x],     B''[x] + 1/B[x]*(A'[x])^2 - 1/B[x]*(B'[x])^2 == 0}; sol = DSolve[eqns, {A, B}, x] 

However, as Mathematica didn’t (couldn’t?) solve this, I transformed it into a system of four first order equations:

eqns = {c'[x] == 2/B[x]*c[x]*d[x],     d'[x] + 1/B[x]*(c[x])^2 - 1/B[x]*(d[x])^2 == 0, c[x] == A'[x],     d[x] == B'[x], c[0] == 1, d[0] == 1, A[0] == 1, B[0] == 1}; sol = DSolve[eqns, {A, B, c, d}, x] 

This still doesn’t work. Weirdly enough, I don’t even get an error message.

I only included the boundary conditions thinking that they may be helpful, but they aren’t part of my original problem.

Your help would be greatly appreciated:)

Solve Matrix equations with Cross Product: weird system of equations

I would like to find the values {Pfx, Pfy, Pfz} that satisfy the equation A X B = C . The code of everything is at the end, I want to ilustrate with images what i think of first:

A is this:

Matrix A

B is this: {0,0,0}

And C is this: {100,500,200}

The image of the complete code is this one:

Complete code

My variable here are {Pfx,Pfy,Pfz} and the {i,j,k} are the unit vectors. The way that the matrix is shown in the picture corresponds with a trick used to solve in papper this type of matrix.

The solution would give me the value of Pfx in the "x" coordinate (and this would be expressed by Pfx being multiplied with the i vector). And the same mechanism applies with Pfy related with j Vector ; and Pfz related with k.

The problem here comes with the fact that the I can`t find the values {Pfx, Pfy, Pfz} that satisfy the equation A X B = C. I am not sure if the problem lies in the "LinearSolve" comand, in the use of the CrossProduct or in the use of the versor {i, j, k} inside the matrix.

Any kind of help in this regard will be extreamly useful, thanks in advance!!

Code:

i := {1, 0, 0}  j := {0, 1, 0}  k := {0, 0, 1}  LinearSolve[({ {i, j, k},{1, 2, 3},{Pfx, Pfy, Pfz}})\[Cross]({{0},{0},{0}}) == ( {{100},{500},{200}} )]    

Securing a replay-based leaderboard system (as much as possible)

A few years ago, I implemented a basic online leaderboard system in one of my games that sent encrypted score data over the wire. The encryption keys were stored in the game client’s binary. Of course, the leaderboards got hacked the same day they were released.

I have now released a new game on Steam, and I’ve worked hard to implement fully-deterministic game logic and a replay system.

The replay system works by simply replaying the user’s input that was recorded in a previous playthrough. The fully-deterministic game logic ensures that the replay will work on any machine, independently of the game’s FPS.

Now, it is time for me to implement online leaderboards.

My idea is to create a server version of the game executable which receives replay files over the network, replays them on some remote machine, and adds the score to a database if the replay data is valid.

While this prevents cheaters from simply sending a fake score to the server, it opens up many other cheating avenues, including:

  • Tool assisted creation of replays, either by slowing down the game speed or by manually crafting a replay file after reverse-engineering its format (the game is open-source).

  • Taking someone else’s replay and sending it over the network, changing data regarding who the replay belongs to.

I could somehow encrypt and compress the replay data before sending it over (or saving it on the user’s local machine), but since the game is open-source, it would be easy to reverse-engineer the encrypted replay format.

What is a good way of securing a replay-based online leaderboard system?

One possible idea I had is to have the server generate an encryption key / token for a specific user which is only valid for a small amount of time, send it over to the client, and only accept replays that are encrypted with that key. This would prevent users from uploading older replays to the server, but in theory it should work — am I missing something?

Another not working 2D collision system

As many before me, I’m trying to make a 2D platformer. The current problem is the collision system. I tried to be smart and use sweeping and line segments to implement this, which ended up somewhat working, but not quite.

Here’s what I’m trying to do:

  1. The player is made of four vertices
  2. The map is made of axis-aligned line segments creating polygons
  3. Calculate the next frame’s position of all four points
  4. Create four line segments from the before/after positions, one for each vert
  5. Intersect these segments with the map
  6. Move the player to the collision point on the axis perpendicular to the wall only

Here’s what happens:

  1. Some walls work just fine
  2. Some walls have collision from the "wrong" side
  3. Some walls have no collision
  4. Some walls stop having collisions when sliding on them
  5. Some walls can’t be moved away from

Here’s the relevant excerpts of my code. Subject to be refactored, I wanted to get this working first.

// Player public class Player extends Sprite {      private PlayScreen scr;      public Vector2 vel;     public Vector2 lastMove;      public Vector2[] verts = new Vector2[2];           public Player(PlayScreen s, float x, float y) {         this.scr = s;         this.setPosition(x, y);         this.setSize(8, 16);         vel = new Vector2(0, 0);         lastMove = new Vector2(0, 0);                  Rectangle r = this.getBoundingRectangle();         float x1 = r.x;         float x2 = r.x + r.width;         float y1 = r.y;          float y2 = r.y + r.height;                  verts[0] = new Vector2(x1,y1);         verts[1] = new Vector2(x2,y2);     }      public void update(float delta) {         float xpos = this.getX();         float ypos = this.getY();          float dx = vel.x * delta;         float dy = vel.y * delta;          this.setPosition(xpos + dx, ypos + dy);         this.lastMove.set(dx, dy);     }      public Vector2 getTR() {         return new Vector2(this.getVertices()[Batch.X3],this.getVertices()[Batch.Y3]);     }      public Vector2 getBR() {         return new Vector2(this.getVertices()[Batch.X4],this.getVertices()[Batch.Y4]);     }          public Vector2 getTL() {         return new Vector2(this.getVertices()[Batch.X2],this.getVertices()[Batch.Y2]);     }          public Vector2 getBL() {         return new Vector2(this.getVertices()[Batch.X1],this.getVertices()[Batch.Y1]);     }      } 
// PlayScreen public class PlayScreen implements Screen {      private OrthogonalTiledMapRenderer renderer;     private Player player;     private Collision collision;      public PlayScreen(MovementGame mg) {                  // omitted cam/viewport setup         // omitted map loading         this.renderer = new OrthogonalTiledMapRenderer(map, 1);         cam.position.set(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2, 0);          player = new Player(this, -50, -50);         collision = new Collision();          for (PolygonMapObject obj : this.map.getLayers().get(2).getObjects().getByType(PolygonMapObject.class)) {             collision.addObj(obj);         }     }      @Override     public void render(float delta) {         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);          player.vel.x = 0;         player.vel.y = 0;          // omitted input handling. sets player.vel to +-100 x/y on arrow key press          player.update(delta);          // omitted debug player drawing         // omitted debug player drawing for next position          collision.doCollision(player, cam);         cam.position.lerp(new Vector3(player.getX(), player.getY(), 0),1f);          cam.update();         renderer.setView(cam);          // omitted debug map drawing     } }  
public class Collision {      public ArrayList<Vector2[]> lines;      public Collision() {         lines = new ArrayList<>();     }      // convert polygon verts to lines and add to list     public void addObj(PolygonMapObject obj) {         float[] a = obj.getPolygon().getTransformedVertices();         ArrayList<Vector2> verts = new ArrayList<>();         for (int i = 0; i < obj.getPolygon().getVertices().length; i += 2) {             verts.add(new Vector2(a[i + 0], a[i + 1]));         }          for (int i = 0; i < verts.size() - 1; i++) {             lines.add(new Vector2[] { verts.get(i), verts.get(i + 1) });         }         lines.add(new Vector2[] { verts.get(0), verts.get(verts.size() - 1) });     }      // detect and resolve collision. camera is for debug drawing     public void doCollision(Player p, Camera cam) {         Vector2 col;         float dx = 0;         float dy = 0;         // try to intersect with every line         for (Vector2[] line : lines) {             dx = dy = 0;             // create the movement line for each vert of the player              // try to intersect it with the currect line             // there HAS to be a better way...             if ((col = getLineIntersection(p.getBL(), p.getBL().sub(p.lastMove), line[0], line[1])) != null) {                 dx = p.getBL().x - col.x;                 dy = p.getBL().y - col.y;             }             if ((col = getLineIntersection(p.getTL(), p.getTL().sub(p.lastMove), line[0], line[1])) != null) {                 dx = p.getTL().x - col.x;                 dy = p.getTL().y - col.y;             }             if ((col = getLineIntersection(p.getBR(), p.getBR().sub(p.lastMove), line[0], line[1])) != null) {                 dx = p.getBR().x - col.x;                 dy = p.getBR().y - col.y;             }             if ((col = getLineIntersection(p.getTR(), p.getTR().sub(p.lastMove), line[0], line[1])) != null) {                 dx = p.getTR().x - col.x;                 dy = p.getTR().y - col.y;             }             // something collided. resolve             if (col != null) {                                  if (line[0].y == line[1].y) {                 // line is horizontal. push player up/down only                     p.vel.x = 0;                     dx = 0;                 } else {                 // line is vertical. push player left/right only                     p.vel.y=0;                     dy = 0;                 }                  // omitted debug drawing                 // finally, update the player pos                 p.setPosition(p.getX() - dx, p.getY() - dy);             }         }     }      private Vector2 getLineIntersection(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3) {         Vector2 res = new Vector2();         if (Intersector.intersectSegments(p0, p1, p2, p3, res)) {             return res;         } else {             return null;         }     } } 

Any ideas or tips on how this could be turned into something working? Or should I give up on this and do grid AABB-collision instead?

Finally, here’s a rare screenshot of the code doing what it should. Blue is the player’s position before the movement, red the intended position, yellow the resolved position and white the distance the player moved too far. screenshot

Same colors, but issue #5. The collision gets resolved onto the wall instead of away.
screenshot2

Thank you in advance for your help! Please excuse the form of this question, this is making me lose my mind…

Problem with EnemyAi system unity keeps giving errors [duplicate]

My EnemyAi system works perfectly but for some reason when I start the game to test it unity keeps giving me errors.

Enemy Ai Script keeps giving me the NullReferenceException: Object reference not set to an instance of an object EnemyAi.Update() error inside unity about the line Vector3 lookDir = target.transform.position - transform.position;

using System.Collections; using System.Collections.Generic; using UnityEngine;  public class EnemyAi: MonoBehaviour {  public bool detected; GameObject target; public Transform enemy;  public GameObject Bullet; public Transform shootPoint;  public float shootSpeed = 10f; public float timeToShoot = 1.3f; float originalTime;  public EnemyAni Animation; public GunAni GunAnimation;  public ParticleSystem muzzleFlash;  public AudioManager Sound;  public PlayerHealth playerHealth;  void Start() {     originalTime = timeToShoot; }  public void Update() {     //makes the enemy rotate on one axis     Vector3 lookDir = target.transform.position - transform.position;      lookDir.y = 0f;      //makes enemy look at the players position     if (detected)     {         enemy.LookAt(target.transform.position, Vector3.up);         enemy.rotation = Quaternion.LookRotation(lookDir, Vector3.up);     }     if (detected == true)     {         Animation.LookPlayer = true;         GunAnimation.ShootPlayer = true;     }      if (detected == false)     {         Animation.LookPlayer = false;         GunAnimation.ShootPlayer = false;     } } 

Enemy character Game Object in the unity inspector:

Enemy Character unity Inspector

Enemy vision Gameobject in the unity Inspector:

Enemy Vision unity Inspector

My organization just to show how everything is attached:

Organization in unity

The error message there are a lot because it’s talking about the other Enemy GameObejcts:

Error Messages

Roll For Shoes – Does the advancement system work for longer campaigns?

I’m about to start in on a new campaign with the Roll For Shoes system, but I’m concerned that the characters will swiftly outstrip basic and intermediate challenges as they grow in dice.

In the title I mentioned "longer" campaigns. I’m defining "longer" as at least 72 hours of game time spread out over maybe 18 sessions, with hopes of room to grow.

Here is an example:

Ryan has Do Anything 1, and begins a life of roguishness. He starts breaking into houses and achieves Skulduggery 2, starts using lockpicks for Tools of the Trade 3, then eventually gets to Lockpicking 4 and maybe Safecracking 5.

Meanwhile, the GM needs to provide appropriate challenges for Ryan. When Ryan starts out, he somehow has to break into a house with one die. If he can manage that, the GM will later need to provide an appropriate challenge for Ryan’s 4-die Lockpicking skill.

From a story perspective the GM can always provide stronger locks and reasons, but by my very rough estimations getting a character to a four die skill could easily happen in a 4-hour session if the game is moving smoothly.

Does the RFS advancement system work for longer campaigns?

How to see which mouse button was pressed (Unity Input System)

I have switched my game to use the new Unity Input System, and I want to know which mouse button was pressed when an action is called.

Here’s how it’s set up: Input System

Whenever one of these three mouse buttons are pressed, the MouseButtonClicked action will fire. I want to somehow know which one of these buttons was pressed from this single action, rather than making 3 seperate actions for 3 seperate mouse buttons.

I have tried reading the values from InputAction.CallbackContext context but I can’t seem to get a proper value from the mouse button which was pressed.

How can I do this?