I am currently developing a math game for my school project. I was wondering if anyone knew how to make Unity perform basic algebra(factoring, multiplying, substitution, etc.). This is the final major part i have to peg down before I can continue with asthetics and smooth gameplay. None of the current or former Unity tutorials mention anything even close to this, so i am wondering-is this even possible?

I imagine quite a few people here know how to make Unity do math. :p

Any functionality you need would be handled by scripting. You have your choice of C# or UnityScript (similar in flavor to Javascript), but pretty much everyone will tell you to use C# if you want to get serious.

I would recommend following any basic scripting/programming tutorial on variables, operators, and functions. Then look for something Unity-specific to see how you can apply that information to your Unity project.

You can be serious with any of the three languages present in Unity. You simply need to realize that the differences between C# and UnityScript are fairly minor. You won't really find it that much easier to use UnityScript over C# and you'll be giving up any external resources available.

As I said in another thread, you can count the number of UnityScript books on one hand but there are dozens of books covering C#. This very much applies to tutorials as well. You may not have noticed but the video tutorials in the Learn section are almost entirely C# with only one covering UnityScript.

I realize that they do have to choose one rather than waste resources making three separate videos, but if UnityScript were really that much easier they'd have likely chosen it. At the very least for their beginner section.

You are entirely correct though in that any basic scripting/programming tutorial will pretty much cover it as these are pretty much universal. If you want something specifically for Unity, you could start with the section they have on scripting.

http://unity3d.com/learn/tutorials/modules/beginner/scripting

This is a fairly new development, isn't it? I feel like all the tutorials used to be UnityScript (I'm thinking in the early 3.x time period). That was one of the main reasons why I went down that road years ago. My thinking was "If that's what Unity is trying to teach me, that's what I should learn!" And also because I just wasn't as comfortable with C# as I was JS.

In any case, so much happier to be working in C# now and I agree with all your other points. :smile:

OP, do you mean something like you can enter an algebraic equation as a string and get it back out simplified/solved/etc, possibly step-by-step? Like this?

That may very well be. I didn't really start using Unity until 4.x nor did I bother using their official tutorials but rather resorted to watching the 3D Buzz tutorials covering the editor and a couple YouTube videos showing scripting in action. I was already familiar with C# when I came here.

The learn section didn't even exist before 4.x.

Okay, but there were still tutorials and code examples available...

Yes!:) I would want, for example, a function displayed and certain parts of it selectable. When selected in sequence, the problem would be solved. The main problem I have so far is the solving. I have 4 basic sets of problems that will all have 1-2 ways to solve respectively, but making Unity do the math to simplify the function is the issue at hand.

Hey. For those of you who aren't Zander, I am with Zander on his project. Unfortunately, I'm new to Unity and know nothing of its functions. I am the story and asset manager for the project.

I will probably be taking replies in his stead, as he has another project he's working on at the moment.

Nice to meet you,

Ylhainen

Hi, @Ylhainen . Would you care to go into a bit more detail about what you guys are trying to do?

@Schneider21 Sure. In essence, we are attempting to craft a game centered on teaching Pre-Calculus concepts, such as limits, discontinuity, and rate of change. In order to make a game to do so without making it a cookie cutter math game, we would like to incorporate "combat" elements. One way we hoped to achieve this is by taking out pieces of "armor" by solving complex problems with different mathematical operations (addition, subtraction, multiplication, etc.)

We had hoped to code the problems to be used into the Unity engine and give the game the capability to turn commands, such as A, X, B, Y, into the operations, while using the right and left triggers to switch between sets of operations to be hotlinked to the buttons.

What we're having an issue with is the mathematical portion of the project. We would like to be able to plug in an equation and have Unity solve it, making it possible for randomized equations with possible answers and answer sequences with each "encounter". Zander already knows how to insert randomized variables and parts of the equations, but these need to be solved before the "encounter" can begin, and hand solving all of the equations would take more time than we have at the moment.

~ Lord Ylhainen

Well with computers, almost anything is possible!

Do either of you have previous experience with programming in any language? Understanding how code works in general will go a great way towards helping you solve your particular problem here. I personally suck at math and dropped Calculus in high school, so I couldn't begin to suss out formulae myself. But the short of it is, if you can generate the formula, you can certainly have your game solve the answer, as long as the "answer" is in a form that works with programming languages.

I don't want to get into too much detail if you guys are already familiar with basic programming terminology. If you are, then I would ask that you dial in more specifically on what you're having trouble achieving. If you're not, it's time to start learning code!

I only know a few things. I did learn the tutorials, and I learned a robot programming language based upon C#. I may not be a pro, but I can do one or two things with a script.

The basic concept is this.

Since our game is mostly focused on limits, I'll use one as an example.

Ax^2 + Ax + A/x+A as x goes to A

The A's represent the random values (0-9) I would be inserting into this one limit type to add diverse enemys with the same general concept for solving them.

Those values are now replaced.

x^2 + x + 6/x+6 as x goes to 5

In order to solve this, the top must be factored, simplified to cancel the denominator, and then the x the limit is traveling to (in this case 5) would have to be substituted. Our goal is to create a system where the player could use an XBOX controller that has these techniques (factoring, canceling, simplifying, etc.) bound to the face buttons. More functions would be available by pressing LT and RT as previously mentioned.

This system is sort of a mix between classic RPG and Lighting Returns. (For those who haven't seen Lightning Returns, see this, *www.youtube.com/watch?v=LExLeRPaNWM )*

As Ylhainen said, I think I know how to substitute in values into the text field. But as for the having Unity know when to factor and cancel, I have no idea. The second I know how to make these math techniques work, I could easily tie in character animation, battle damage, etc. From what you're saying though, it sounds like I would have to teach Unity Pre-Calculus.

AFAIK Unity doesn't have a a pre-included library to handle this.

But since you have access to C# in unity, you can either roll your own solution or find an existing library that handles this for you and include that in your project.

Try searching Codeplex, Codeproject, Stack Overflow, etc for algebra and C#.

There seems to be a few packages floating around, e.g. mathdotnet (it's F# but if you compile it to a DLL you can include it since it's .NET, as long as it doesn't require 4.5).

Yes, and you're right that the focus of what was available was largely on UnityScript.