Problems with using lissajous curves for sniper scope sway

I like to pick apart games in my spare time and recreate some mechanics from simple to complex which I think would be fun. The game I mainly pick apart is Call of Duty 4: Modern Warfare because of its large modding community and mod tools which make it easy to learn how the game works. The in-game developer console also makes it easy to debug the game on my own as well.

One of the mechanics I am currently trying to pick apart is the sniper scope. One thing I noticed right away is the sway pattern which is a lissajous pattern. I quickly implemented my own lissajous pattern which is the classic figure-8 used in most games and applied it to the camera. Here is the script:

using UnityEngine;  public class ScopeSway : MonoBehaviour {     public int a = 1,                b = 2;      private float size = 1f,                   speed = 0.5f,                   time = 0,                   posX = 0,                   posY = 0;      void Update()     {         time = Time.time * speed;         posX = size * Mathf.Sin((a * time) + (Mathf.PI / 2));         posY = size * Mathf.Sin(b * time);          Vector3 offsetX = transform.up * posX,                 offsetY = transform.right * posY,                 offsetZ = transform.forward * transform.position.z;          transform.localPosition = offsetX + offsetY + offsetZ;     } } 

One thing I want to get out of the way is that if you visualize the figure 8 the height and width are the same size, so instead of making a width and height I merged them into a single size variable which makes a perfect square. The a and b variables modify the frequency which allow you to make more curves instead of a figure-8. Using this source you will be able to plug in your own a and b values from the patterns you see. This is also the source I used when writing this script.. The script doesn’t have any problems, it does exactly what I wrote it to do. However, there is one micro detail and core mechanic I am failing to recreate.

For those that have played the game and have access to it there is one thing you probably have never noticed until you actually spot what is happening. In the game whenever you are looking through the sniper scope you will notice that the scope sways like normal. However, no matter how close or how far whatever it is that you are aiming at the size of the curve pattern is the same. In order to visualize this, take the script I pasted here and put it on a camera and place a cube 100 meters away, also set your cameras FoV to 15 (CoD 4 uses 15 FoV for sniper scopes). The scope will seem like it sways normally but not until you move the cube directly in front of the camera. Now you will notice that the camera sway is huge on targets up close but small for targets far away. In CoD, the sway amount is the same no matter how far or how close you are to what you are aiming at. What exactly is going on here?

After thinking about it I thought that maybe they are changing the size of the pattern based on the distance of where you are pointing. So I decided to add a raycast for up to 100 meters and change the size of the pattern based on the returned hit distance. It failed miserably. It created lots of stuttering and snapping motions which where very visible and hard on the eyes. After that I thought that maybe I can just interpolate between the two points but that won’t work because in CoD it does not look like the view is being interpolated, the sway does not even make a single twitch. If you take my script and aim at the corner of the object and let the sway point off of the object the sway amount goes all the way back up, which does not happen in the game.

I do not know what I happening or how they are achieving this effect. I do know that the sway is programmatically done and is not using an animation because the sway has the same pattern as the gun sway when aiming from the hip. Whenever you scope in and scope out the scope does not start at the same place every time, it starts at a different place which means it is using lissajous curves based on a factor of time.

My question for you guys is, how are they achieving this and what am I doing wrong? I have spent five days now researching and picking apart some open source games but I have not found an solution or even a hint. It seems like this topic isn’t really well covered because it is a mechanic no one notices and we all take for granted, but it is the most important polish for full screen sniper scopes. How do I make the sway pattern the same size and speed no matter how far or how close it is that I am looking at.

A better explanation of what is going on is if you zoom in CoD right in front of a wall the scope will only sway in a box of lets say 20 pixels. And when you zoom to something far out it still only sways in a box of 20 pixels. My script will sway in a box of 20 pixels when aiming at things 100 meters away but when zooming in on things directly in front of the camera the camera will sway in a box of 100 or more pixels. I want my camera to sway in a box of 20 pixels or so no matter how far or how close the object you are aiming at is. It’s almost like they are shifting the cameras viewport and not the physical camera?

Unity C# XML Serialization broke when abstract base type is added

I had a menu system with 4 different item types instantiated from one XML file. I had always intended to build an abstract base class for them to inherit from, after I knew what the common elements would be. When I wrote the simple base class, and assigned the 4 existing items as derived classes, everything broke! The GameObjects with my instantiator scrips kick this error, now:

InvalidOperationException: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. UnityEngine.Transform does not implement Add(System.Object) 

I read a lot about why it could happen, but like I said, it wasn’t happening until I build a new, very simple abstract class for the items to inherit from.
Any help understanding “why” would be awesome!

How to generate random waves for a bullet hell game that feel balanced and natural

My game consists of ‘waves’ of objects called ‘spawners’, which once every certain amount of time (their firetime), move to a new place on the screen and spawn an enemy. Each wave has 4 important properties:
1: the amount of spawners the wave has
2: the interval of time between creating new spawners
3: the total length of the wave
4: the types of spawners that can appear in a wave (represented as a std::vector<std::pair<std::string, int>> where the string is the spawner name, and the integer is its spawn weight.

The game works by picking a random spawner from the possible spawner types (with a weighted rng) every new spawner interval. Currently waves are set and are loaded from a file at runtime.

My problem is that I cannot find a good way to randomly generate waves that feel balanced and natural. Currently, I am trying to generate waves based on a difficulty value, mostly using weighted random number generation. However, this does not produce balanced waves that correspond well to the target difficulty. Even after trying several different techniques, I am unable to get a system that generates waves that fell balanced and natural (like the ones hand made).

Is there any way to generate waves that feel natural, based off of the difficulty value? How should I approach this problem?

Also if its of any help, each spawner also defines its own difficulty value.

Why are there no in game time subscription options?

Many games employ a monthly subscription to play a game. However, this makes coming back to a game pretty difficult, as you are most likely unsure of whether you will be playing the game for a few months or a few days.

Why are there no games where you subscribe for in game time (or why is it not common practise)? That would allow returning players to either have some game time left when they return, or not feel so bad for buying more game time in the case they end up playing the game for only a couple of days. I believe a monthly subscription could exist alongside an in game time subscription. Currently, this is stopping me from playing a couple of games.

How can I rotate a cylinder so the top points at specific transform?

I have a GameObject with a LineRenderer that has a single line drawn, on which I’d like to place cylinders so the top of the cylinder points to each end of the straight line that the cylinder sits on, like a cylindrical bead on a straight piece of string. The cylinder is a child of the GameObject which the LineRenderer is sat on. The LineRenderer GameObject is not rotated itself, and the Line drawn could be any angle relative to the GameObject, and it would be a bit of a hassle to refactor so that the Line is always vertical and instead rotate the LR GameObject, and it seems this should be an easily solvable problem! I’m attempting to use either LookRotation or LookAt on the cylinder but for whatever reason all permutations I can think of simply are not working. THanks for any advice!

How many 2d rigidbody can work in android? [closed]

I’m making 2d side scroller shooter with Unity. There are 2 main things that have rigidbody2d: Characters and weapons. Characters are player and enemies, and weapons are just weapons.

However when I run the game, frequently lag spike happens, and in my android phone is worse. So I opened profiler and in the moment game goes really slow, there are lots of Physics2D stuffs working. In that moment, there was 80 rigidbodies(and 60 is active, and rest is sleeping).

I can find using physics in mobile is quite heavy very easily. Is this bad idea to exists 80 – 100 rigidbodies in android device?

Also currently I try to find some alternative, not use physics to move character but couldn’t find any helpful information. Even Unity’s official tutorial uses Rigidbody to move character. If I don’t use rigidbody and collider, how do I implement character stuck in the wall or something? Any advice will very appreciate it.

How do I continue a smooth stroke around a corner in zBrush?

I have been trying to create a series of smooth lines down the outside of a bell shape, around the lip, and then back up the inside. The problem is that I can’t seem to accomplish this in a single brush stroke, and every time I’ve tried to join up multiple strokes, the join always looks really obvious.

enter image description here

Is there any way to “pause” a stroke so that you can rotate your view, and then resume it smoothly? Or is there any other way in general to go about something like this?

Java 2D Game-Building a TileMap from a Text File-> How to load a separate map

This is likely a very simple question, but I am very new to game development so I am running into some issues. I have a text file that I am using for my map for the tiles to be allocated. This works fine, but I am running into issues figuring out how I would go about loading in a different part of the map. For example, say I wanted the character to go into a cave or building, what would be a good way to go about loading this new area. Right now I have my handler class setting the world in my game state class, and I have tried messing around in the game state class to try and accomplish what I want but have not had much success. In that game state class I have a tick and render method, and in the constructor I have it being set The methods that I have tried have resulted in a new map to be loaded in, but the other map is still loaded in under this, and I know this because the character has collisions set up. This also goes along with this issue, but what would be a good way to trigger this loading of the new section of the map. Any help would be greatly appreciated. Below is the code in my GameState class. (changeWorld is based off of the X coordinate when in game, and once you reach a certain point it switched maps, this was just done for testing because it is not an accurate way of doing it).

World1 = new Worlds(handler,”resources/Worlds/world1.txt”);

SpawnWorld = new Worlds(handler,”resources/Worlds/world2″);

if(Worlds.changeWorld() == false) { handler.setWorld(World1);

else if(Worlds.changeWorld() == true){ World1=SpawnWorld; handler.setWorld(World1); entityManager.setPlayer(new Player (handler, 0,0));} }//end contructor

public void tick() {
if(Worlds.changeWorld() == false) { World1.tick();
} else if(Worlds.changeWorld() == true){ World1=SpawnWorld; handler.setWorld(World1); SpawnWorld.tick(); }
}//end tick

public void render(Graphics g) { if(Worlds.changeWorld() == false) { World1.render(g);}//end if

else if(Worlds.changeWorld() == true){         World1=SpawnWorld;         handler.setWorld(World1);         World1.render(g);      }//end graphics