game creator: cars bounce / jump at the end of each lap

When I use the path_start function like this: path_start(circuit,velocity,path_action_continue,true);

When completing each lap, the cars jump (I don't know if it's the correct term in English), see the image below:

enter the description of the image here

I did some tests and I realized that this jump directly influences the lap time.

At first I thought this was because at the moment the car touches the finish line, I change its speed to make a new lap time, but even the speed is unique.

Modify the use of the path_start function (path_start(circuit,velocity,path_action_stop,true);, with that I have to start the function every time the car collides with the finish line) I neutralized the jump, but this generated other problems for the operation of my game.

How to prevent cars from making this jump?

Unit: How do I start a new game using a UI button logic code?

My hierarchy has 3 main GameObjects:

  1. Game data where all game objects are stored as child elements of the Game Data GameObject.

  2. Main menu and all main menu objects stored as secondary elements in the main menu game object.

  3. Game Manager GameObject that has a script that controls the game like pausing the game or going to the main menu.

Hierarchy

By default, game data is disabled and all game objects are also disabled. Then, when I start the game with the main menu, when I click on the button to start a new game, I'm just activating the Game Data object:

This script is attached to the Main Menu:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour
{
    public GameObject gameData;

    public void StartNewGame()
    {
        gameData.SetActive(true);
    }

    public void ResumeGame()
    {

    }

    public void QuitGame()
    {
        Application.Quit();
    }
}

This is working for the first time starting a new game.

And this script is attached to the GameObject of Game Manager:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameController : MonoBehaviour
{
    public static bool gamepaused = false;

    public GameObject gameData;
    public GameObject mainMenu;

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            gamepaused = !gamepaused;

            if (gamepaused)
            {
                Time.timeScale = 0f;
            }
            else
            {
                Time.timeScale = 1f;
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            gameData.SetActive(false);
            mainMenu.SetActive(true);

            Time.timeScale = 0f;
        }
    }
}

This script is working Pressing the P button the game stops / continues.
When you press the ESCAPE key, the game also stops but also returns to the main menu by changing the game objects to disable / enable.

Now let's say I pressed the escape key while playing and returned to the main menu. Now I want to start a whole new game, but by clicking on the StartNewGame button.

The problem is that this time I don't just want to activate the Game Data as I did before:

gameData.SetActive(true);

This time, at least in my logic, I want to destroy the existing game data and instantiate a new one using a prefabricated one that I already have of the game data.
This is my logic, but I'm not sure how to do it. Or something like that.

The main objective is to be able to start a new game every time you click on the StartNewGame button.

unity – Suggest me a great game kit for zombie fps

Thank you for contributing a response to Game Development Stack Exchange!

  • Please make sure answer the question. Provide details and share your research!

But avoid

  • Ask for help, clarifications or respond to other answers.
  • Make statements based on opinion; Support them with references or personal experience.

Use MathJax to format equations. MathJax reference.

For more information, see our tips on how to write excellent answers.

Color: Detect the type of screen my Unity game represents

I am working on a multiplatform Unity game for iOS, Android, stand-alone and consoles too.

Especially between the independent and console versions, it is clear that the colors of the game are different (I guess because of the screen).

For that reason, we make a color classification through a post-processing layer, and then let the player adjust it in the settings (saturation, contrast, etc.) as many games do.

But at least, we want to have a series of pre-established rating profiles that the game will use by default according to the type of screen, such as LCD, LED, OLED, etc.

Is there any way to know through the code what type Display is currently being used to render the game? It seems that I can only get the resolution with the Screen class.

Game – Rock, paper, scissors in C ++

It's a good start! Here are some things that can help you improve your program.

Do not abuse using namespace std

putting up using namespace std At the top of each program there is a bad habit that you would do well to avoid. Know when to use it and when not to do it (such as when writing include headers). In this particular case, I think it is perfectly appropriate because it is a unique short program that is not a header. Some people seem to think that it should never be used under any circumstances, but my opinion is that it can be used as long as it is done responsibly and with full knowledge of the consequences.

Use instead of

The difference between the two ways is that the first defines things within std:: namespace versus in the global namespace. Language lawyers have a lot of fun with this, but for daily use I would recommend using . See this SO question for more details.

Use for loops instead of while loops where practical

your gameloop the routine can be simplified a bit using a for loop instead of a while tie. Here is the current code:

void gameLoop() {
    auto quit = false;
    while(!quit) {
        // other stuff
        quit = shouldGameExit();
    }
}

I recommend writing it as a for loop to do several things. First, change the scope of the quit variable to only within the loop. Second, make it clear how the exit condition is established:

void gameLoop() {
    for (auto quit = false; !quit; quit = shouldGameExit()) {
        // other stuff
    }
}

Do not use std::endl if you really don't need it

The difference between std::endl and 'n' is that 'n' only emits a newline character, while std::endl actually wash the current. This can take a long time in a program with many I / O and is rarely really needed. Is better only use std::endl when you have a good reason to empty the transmission and it is not very necessary for simple programs like this. Avoid the habit of using std::endl when 'n' You will pay dividends in the future as you write more complex programs with more I / O and where performance should be maximized.

Verify return values ​​and handle errors

The code calls getline but never check the error return values. Yes getline find a problem, set the failbit. It is easy to verify this in C ++, due to operator overload. That is, one could do this:

getline(cin, input)
if (cin) {  // if getline was OK
    ///
}

Think of the user

Generally speaking, it is not unusual for users to write defective entries. For that reason, I think I would not throw an exception of with getUserChoice. Instead of abruptly aborting the user outside the program, a friendlier way to do so would be to give the user the opportunity to correct the entry. Here is a way to rewrite that function:

Choice getUserChoice() {
    Choice userchoice;
    for (auto valid{false}; !valid; ) {
        cout << "Rock, paper or scissors? n";
        string input;
        getline(cin, input);
        if (cin) {
            if(input == "rock" || input == "ROCK" || input == "1" || input == "r" || input == "R") {
                valid = true;
                userchoice = rock;

            } else if(input == "paper" || input == "PAPER" || input == "2" || input == "p" || input == "P") {
                valid = true;
                userchoice = paper;
            } else if(input == "scissors" || input == "SCISSORS" || input == "3" || input == "s" || input == "S") {
                valid = true;
                userchoice = scissors;
            } else {
                cout << "Sorry, I didn't understand "" << input << ""n";
            }
        }
    }
    return userchoice;
}

Keep in mind that one could code a return instead of using the userchoice and valid variables, but I prefer to have an easier to read program flow without having to search return statements. You can decide for yourself which flavor you prefer.

Make sure all routes return a value

the decideOutcomeOfGame The routine returns the result of the game. Their probable that all combinations are listed, but I would rather make sure that the function returns something every time. This is how I would write it.

Outcome decideOutcomeOfGame(Choice userChoice, Choice botChoice) {
    if (userChoice == botChoice) {
        return draw;
    } else if ((userChoice == rock && botChoice == paper)
              || (userChoice == paper && botChoice == scissors)
              || (userChoice == scissors && botChoice == rock)) {
        return bot;
    }
    return user;
}

Consider using a better random number generator

You are currently using

auto randomNumber = rand() % 3 + 1;

I usually recommend the use of C ++ 11 std::uniform_int_distribution to replace the old style rand() but since you are using C ++ 17, you could use std::sample. This reduces the getBotChoice() function for this:

Choice getBotChoice() {
    constexpr static std::array choices{ rock, paper, scissors };
    static auto rnd{std::mt19937{std::random_device{}()}};
    std::vector botChoice;
    std::sample(std::begin(choices), std::end(choices), std::back_inserter(botChoice), 1, rnd);
    return botChoice.front();
}

Now there is no need for throw because the code will never generate an invalid return value.

Use std::string_view where practical

Instead of mutable strings, the global variables outcomeMap and choiceMap would be better expressed as a std::array from std::string_view. In other words, instead:

string outcomeMap(3) = {"You win!", "Bot wins!", "It was a draw!"};

Write this down:

constexpr array outcomeMap{"You win!", "Bot wins!", "It was a draw!"};

Consider encapsulating in a namespace

It does not seem that these functions are useful without the other. Because they are so closely related (and also related to data), I would recommend consolidating everything in one namespace.

Understand return 0 in principal

When a C or C ++ program reaches the end of main the compiler will automatically generate the code to return 0, so it is not necessary to put return 0; explicitly at the end of main. I advocate omitting it to reduce clutter and let the compiler generate code; others prefer to write it explicitly. It is up to you to choose which style you prefer, but you must know this compiler behavior anyway.

Simplify your code

The code currently contains this construction:

if(input == "no" || input == "NO" || input == "n" || input == "N" || input == "0") {
        return false;
    } else {
        return true;
    }

As @Deduplicator correctly observes in a comment, it would be best to simply return the value of the expression that is already bool:

return input == "no" || input == "NO" || input == "n" || input == "N" || input == "0";

Unity Game too dark in Samsung Galaxy Alpha (LWRP)

I just noticed that my game is too dark in my old Samsung Galaxy Alpha. The game looks good in the editor, the PC version and my Samsung Galaxy S7.

I have been developing with Unity 2019.2.2f1 so far and I read that some versions had this problem that I have in previous versions, but that it should have already been patched. I updated to 2019.2.15f1 just out of despair, but the problem remains the same.

It is an LWRP project and I still have no idea of ​​lighting. So far no lights have been added to the project and I am mainly using GUI elements in the game instead of sprites.

View post on imgur.com

View post on imgur.com

I don't have much experience with quality settings and stuff, so I'm not sure what configuration to post. Please let me know which sections are important and I will edit the publication accordingly.

Object-oriented: how to design different movements of different pieces of a chess game using OOP directors?

I'm trying to design a chess game where every piece of the game inherits from a abstract Piece class.
The piece only does a few things:

  • Indicates what color it is (white / black)
  • It says what kind it is
  • Indicates whether a movement is valid or not.
  • and maybe what cell / square on the board is currently

Previously I was thinking of making the validation part of the piece itself so that there was a abstract validateMove() method that each piece would have to implement, but this could lead to many code changes if, in the future, I decide to change the movement validation mechanism of a specific piece, something similar to the case of rubber duck no flight method described in the Head First Design book.

Therefore, I thought about creating this Interface called MoveValidator, which would have specific implementations of each piece and each piece would have a validator as one of its variables instead of being a validator in itself or implementing the validation itself.

then a Pawn would have a PawnMoveValidator As one of its composition.

Then I have the following Abstract piece class

@RequiredArgsConstructor
public abstract class Piece {

    @NonNull
    @Getter
    private final PieceColor pieceColor;

    @NonNull
    @Getter
    private final MoveValidator moveValidator;

    @Getter
    @Setter
    private Point currentLocation;


    private boolean basicValidation(Cell()() board, Point src, Point dest) {
        .........
        .........
    }


    public boolean validateMove(Cell()() board, Point src, Point dest) {
        return basicValidation(board, src, dest) && moveValidator.validateMove(board, src, dest);
    }

}

Cell.java

@RequiredArgsConstructor
public class Cell {

    @NonNull
    @Getter
    private final CellColor cellColor;

    @NonNull
    @Getter
    private final Integer row;

    @NonNull
    @Getter
    private final Integer col;
}

Point.java

@RequiredArgsConstructor
public class Point {

    @NonNull
    @Getter
    private final Integer x;

    @NonNull
    @Getter
    private final Integer y;
}

MoveValidator.java

public interface MoveValidator {

    validateMove(Cell()() board, Point src, Point dest);
}

So I have some questions here.

  1. Is this a good design or can it be further improved?
  2. If he Piece It has no abstract method to implement, should it remain an abstract class or become a concrete class?
  3. What happens if the validation of movement of a specific piece requires knowledge of the state of that specific piece for which it is implemented?
    For example: the pawn wants to move two cells forward. the Pawn The class has a flag that indicates whether it is the first movement or not. In that case, if the PawnMoveValidator I wanted to validate the movement, I would need to know the state of the flag. How can it be possible without having the Pawn class implement the validator?

Thanks for your time

Game design: how to prevent manufacturing costs and sales prices from converging on economies?

There is a pattern in player-driven economies, where production (or processing) costs and sale prices of items converge at a point where the profit margin becomes tiny or even negative. Some examples I can think of are World of Warcraft and Eve Online, but I'm sure you can also recognize this pattern in other games (mainly MMO).

A simple example:
Reagent costs for a potion of life are 1.0 gold in total.
The manufacturing process requires only a few seconds.
Putting an item in the auction house costs 0.1 gold.
The price of the auction house ranges from ~ 1.1 gold.
The total expected benefit is around ~ 0.0 gold.
The player invested 200 gold to achieve the manufacturing skill necessary to produce it.

In EVE Online, players are forced to have great production and marketing skills to have any earnings at all. For newcomers it is almost impossible to carry out any activity related to production that is worthwhile or remotely.

Why is this a problem?
It makes processing more expensive than beneficial in most cases. However, players should be encouraged to do crafts as a secondary activity, and not be financially punished for practicing it.

So, a solution that comes to my mind is to create a better elaboration system (but how?). However, the fundamental issue could be the natural effects of market economies. It is not unknown for the real economy to follow the same pattern. It is a pricing mechanism to avoid excessive saturation and challenge business sustainability: if your product costs more than your production, that business is not sustainable; And if there is too much competition, you should set your prices too low to keep up.

Let's continue with WoW and EVE Online as basic reference examples.
The questions are:

  • Is this a problem that deserves to be solved? Can it be fixed on a large scale?
  • How can you solve it, or at least reduce that price pattern?
  • Is there any way that this solution remains based on the free market and directed by the players?

gn. General topology: can I win this variant of the game Banach-Mazur

Suppose I play the next game against the opponent. My movements are rational numbers $ p_i $ and the opponent's movements are real numbers $ epsilon_i> 0 $.

In turn $ n + $ 1 the sequence of the past movement is $ p_1, epsilon_1, ldots, p_ {n}, epsilon_ {n} $. I select a point $ p_ {n + 1} in mathbb Q cap (p_ {n} – epsilon_ {n}, p_ {n} + epsilon_ {n}) $ and the opponent selects some $ epsilon_ {n + 1}> 0 $.

I always win that the sequence $ p_i $ It tends to an irrational number.

Does anyone know if I have a winning strategy? I certainly do not do so if the rational and irrational numbers are exchanged, since the opponent can only enumerate the rational ones and select the intervals small enough to exclude each rational in turn.

I imagine I can always win. But that is only because this looks like the Banach-Mazur game, which I can win if the goal set is irrational.

The motivation behind this is that I want to recursively build a set of homeomorphisms $ F_1, F_2, ldots: mathbb R to mathbb R $ such that $ F (x) = displaystyle lim_ {n to infty} F_n circ F_ {n-1} circ ldots circ F_1 (x) $ It is a well-defined homeomorphism and such that some fixed $ p in mathbb Q $ It is sent to an irrational number.

I have conditions under which the limit exists. That is, I have to ensure the next $ max d (x, F_n (x)) < epsilon_n $. Unfortunately $ epsilon_n $ They don't know each other beforehand. Every $ epsilon_n $ It is determined by $ F_1, ldots, F_ {n-1} $. This leads to the previous game where $ p_n = F_n circ F_ {n-1} circ ldots F_1 (p) $.

Is using the Observer pattern a good idea when building a chess game?

I am trying to design a chess game using OOP concepts that have a user interface element. My idea is to show the number of squares / cells to which a piece can travel when selected. Basically I want to show the paths / directions in which you can travel / attack in a different color.

Something like the following

(enter the description of the image here)

Then I designed a summary Piece class, which among others, has a Map object that keeps track of all the cells to which you can travel in the direction, something like this
Map>

Now, let's say a piece of the Queen's own team is on its way to attack in the FORWARD address and you put in the cell that is in chessBoard(6)(4)

What better way can I notify the Queen Or any other piece that observes that particular cell of the event so that each piece can call its own update method and redraw its attack path?

I was thinking of following the pattern of the Observer where each cell will be a subject and only the pieces that will observe them will be observers. Then, in any case, something happens in any of the cells observed by a particular set of pieces, only those pieces will be notified.

But then I'm not sure if this is a good approach, since I have to have a maximum of 32 listeners for each cell. Not sure if it will be scalable at all.

Is there any better way to do it?

Thanks for taking the time to read.