Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

I want to learn about all maths in C# in Unity!

Discussion in 'Scripting' started by sevdigim1451, Jun 21, 2022.

  1. sevdigim1451

    sevdigim1451

    Joined:
    May 2, 2020
    Posts:
    40
    Can you give me any advice about all maths skills in Game Development, How can I calculate degrees, counts, negative and positive and what you know about Maths in Unity? İf you share about this topic may be YouTube videos, courses , websites or articles etc. It will be good for me! Thanks for all responses!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Start making games. You'll see what maths are involved.

    This guy also has an opinion:

     
    All_American and Bunny83 like this.
  3. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Look for Freya Holmer on youtube.
     
    Kurt-Dekker likes this.
  4. sevdigim1451

    sevdigim1451

    Joined:
    May 2, 2020
    Posts:
    40
    Thanks for this reply!
     
    Last edited: Jun 22, 2022
  5. sevdigim1451

    sevdigim1451

    Joined:
    May 2, 2020
    Posts:
    40
    Thanks!
     
  6. bplc

    bplc

    Joined:
    Mar 10, 2022
    Posts:
    104
    In the same way that an astronaut does mathematics or a scuba diver..
    Mathematics, Rest of Mathematics.


    Here you will call the whole numbers : int (integer)
    and the decimals : float.


    Variables allow you to store information like numbers.
    Vector3 is a variable allows you to store 3 pieces of information (often used for store XYZ coordinates)

    You can use this for angles for example :
    https://docs.unity3d.com/ScriptReference/Vector3.Angle.html
    https://docs.unity3d.com/ScriptReference/Vector3.SignedAngle.html


    You also have the symbols :

    https://docs.microsoft.com/en-gb/dotnet/csharp/language-reference/operators/
    In this page you have several links to the different operators, you can find there, the arithmetic operators.


    If you want to test calculations by yourself :

    • You create a unity project.
    • You create a script that you put on an object of your game, and you write this in it :
    • print("my result is =" + (-1-1)); 
    • Enter the Update tag if you want a result at each tick, or Start if you want the result only once at the start of the project, the result will appear in the console.
    For this calculation my console marks me :
    "my result is =-2"


    just enter your calculation between the parentheses around the -1-1, and you can start testing for yourself.
    print("my result is =" + (Your Calcul));


    To put it simply, in a 3D engine or computer, everything is calculated, the distance between two objects, the reflection of a shadow in relation to the angle of the lighting, the pixel that lights up on your screen...

    The Quaternions :
    https://docs.unity3d.com/ScriptReference/Quaternion.html

    • Bezier curves,
    • Linear interpolation,
    • trigonometry
    • ...
    It would be easier to list everything unrelated to math xD
    Even a boolean can be interpreted as a binary system (0,1) / (true, false).
     
    Last edited: Jun 28, 2022
    TheDevloper and sevdigim1451 like this.
  7. bplc

    bplc

    Joined:
    Mar 10, 2022
    Posts:
    104
    I forgot here you can find the math functions :

    https://docs.unity3d.com/ScriptReference/Mathf.html

    Example of use :

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class nameOfMyScript: MonoBehaviour
    4. {
    5.     int myVariable = 360;
    6.     void Start()
    7.     {
    8.         print("my result is =" + Mathf.Sqrt(myVariable));
    9.     }
    10. }
    Mathf.Sqrt means: square root.

    Here myVariable = 360

    Mathf.Sqrt(myVariable) = √(myVariable) = √360 18,97367 ;)
     
    TheDevloper and sevdigim1451 like this.
  8. sevdigim1451

    sevdigim1451

    Joined:
    May 2, 2020
    Posts:
    40
    Thanks for all these informations and thanks for your all replies!
     
  9. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    If you're looking for more broad areas, Trigonometry and Physics are two areas which I use a lot when writing code for games, and sometimes even early Calculus. If you were to take some classes, I would start with those.
     
    sevdigim1451 likes this.
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Adding to that, the main point of "maths" in game engineering is to model the problem so you can solve it.

    You don't want to focus so much on "how do I get the square root of 3 squared plus 4 squared?" as you want to focus on "what does the Pythagorean theorem really do for me?"

    "Maths" is just a mental tool to let you abstract problems into models that you can solve with a program.
     
    sevdigim1451, bplc and Ryiah like this.
  11. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,923
    It will depend on the game. If you want to hand-make a nice springy back-and-forth motion, you can probably use a physics Spring (don't need any math), but you can also use sin waves (which one of those tutorials looked like). If things will be connected at funny angles during the game, or the player can rotate things in various ways, you may need to know game Quaternion math. If you want interesting random rolls (like 5 to 15 but mostly around) that's 7th grade math but you may need someone to help explain game statistical randomness curves (or you could use Unities curves, and learn no math).

    Obviously, if you're making an idle game where you need 10e+75 gold to upgrade this and that, you'll need to be decent with logarithms (which make it so buying 100 more silver mines becomes more and more expensive). If you're making a matching game then you only need enough math to know if tiles are 3.5 wide and start at -5, then tile j goes at -5+(j-1)*3.5.

    A lot of the math which people say you need to know, is obsolete (you needed it for simpler game engines, but now Unity does it for you). For example, trigonometry and matrixes.
     
    sevdigim1451 and Ryiah like this.
  12. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Even for the simplest 3D games, you'll eventually need to learn at the very least the basics about vectors and what their operations do (addition, substraction, dot product, cross product, etc).
     
    sevdigim1451 likes this.
  13. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,923
    Dot product is one of those obsolete things -- 99% of the time it's to get the angle and Unity's Vector3.angle does that better. Sure, vector math is useful in many types of games hand-placing stuff along funny directions. I thought so when I wrote about 100 pages covering it from the ground up. But many games won't need it. Cross product is more vector math, but only for really complex placements or use of angleAxis.
     
    sevdigim1451 likes this.
  14. sevdigim1451

    sevdigim1451

    Joined:
    May 2, 2020
    Posts:
    40
    Thanks for all these replies, they help to occur new things. I solved a lot of problems until now. I was forced about calculating when I tried to make game mechanics, camera follow system or AI systems. I want to finish all of them.