Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
10

Transitioning a 2D Line in a Linear / Quadratic Graph? [closed]

Asked by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago
Edited 5 years ago

Hi everyone. I have been for a while now, creating my game. I wanted to incorporate the usage of Graph to give player a better understanding about the physics of the game.

Which scenario to use a Graph?

As I am creating a FPS game, I want to make it as realistic as you can get in . Probably not that realistic but works for now. Anyway, I enjoyed playing Phantom Forces a lot. But I realized that it does not have weather effects on the game. I thought this would be a brilliant idea and wanted to create a Realistic FPS Shooter. During that time, I realized that the weather does take on effect on the accuracy, stability, gun swaying and other realistic aspects. To show the balance performance of the gun, I decided to create a running graph, showing the gun performance.

About the Graph

So the graph updates every 5 seconds. The relation of the graph is to show the Gun Stability, which uses a range from 1 - 7, 1 being all round horrible and shown in colour Red and 7 is specific portion of the gun is damaged. 5 is the normal range and the most common range.

Now, I was working on it. Things were going smooth. But then, I came across a problem which I have no clue on solving it.

When you see an actual graph, you see that it is smooth. There are many smooth options in . However in GUI (Graphic User Interface), the only one that I know of is TweenService. The parameters of TweenService are

UDim2 endSize

UDim2 endPosition

EasingDirection

EasingStyle

float Time

bool Override

CallBack function

However it does not take into account for the Rotation of GUI's. The Rotation of Gui should already be specified before tweening it. I have bunch of dots in my Screen and I want my lines to be pin point accurate in the Screen.

I have tried doing the following example below.

frame:TweenSizeAndPosition(UDim2.new(0.6, 0, 0, 9),UDim2.new(0.157, 0, 0.486, 0),"Out", "Quad", 3)

The (0.157, 0, 0.486, 0) is the actual position of the frame. No this does not work. It slides down. Graphing cannot have any errors. Also, I do not want to define the Rotation beforehand. So how would I get around this???

In case you did not understand what Frame refers to; it is the line which represents the ratio.

[EDIT] Why the GUI TweenService will not work

Now. Gui TweenService does not take into account for the rotation which leaves me in two options. Either rotate it beforehand, or after the tween is played. By doing it afterhand, the whole animation looks horrible, and not very professional. If i did it beforehand, the graph would slide down because the properties changes due to the rotation defined previously.

Any Suggestions on how I should achieve this? Let me know if the information I provided is not sufficient. Thank you for reading this.

0
Do you just need to connect the dots on the graph with a gui line? mattscy 3725 — 5y
0
not quite. The dots are just there to help me position my frame according to the Gun Stability. So no. Zafirua 1348 — 5y
0
Try using TweenService. Not the Tween API for UIs. TweenService allows you to smoothly transition properties to certain points. Try using that and change rotation using it as well. Also, if you want smoothness, use RunService. It can help you get smoothness, like the .RenderStepped() event is pretty smooth. Although, be aware, because RunService can only run locally. KingLoneCat 2642 — 5y
2
What do you mean tween service doesn't take rotation into account? You can animate any numerical property with tween service: https://gyazo.com/834232da1c0819888ca7caa6df8d9bf0 ScriptGuider 5640 — 5y
View all comments (2 more)
0
Tween service does work with rotation, as it can take Vector3 values as parameter. Le_Teapots 913 — 5y
0
Thanks to KingLoneCat and ScriptGuider for their effort. Although there are some bugs that still persists, I am more than capable enough to deal with those. I had assumed that TweenService only worked for Parts and TweenSizeAndPosition only for GUI. Thank you for your help. Zafirua 1348 — 5y

Locked by User#21908 and TheeDeathCaster

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
-5
Answered by 5 years ago

In elementary algebra, the quadratic formula is the solution of the quadratic equation. There are other ways to solve the quadratic equation instead of using the quadratic formula, such as factoring, completing the square, or graphing. Using the quadratic formula is often the most convenient way.

The general quadratic equation is

{\displaystyle ax^{2}+bx+c=0.} ax^{2}+bx+c=0. Here x represents an unknown, while a, b, and c are constants with a not equal to 0. One can verify that the quadratic formula satisfies the quadratic equation by inserting the former into the latter. With the above parameterization, the quadratic formula is:

{\displaystyle x={\frac {-b\pm {\sqrt {b^{2}-4ac}}}{2a}}.} {\displaystyle x={\frac {-b\pm {\sqrt {b^{2}-4ac}}}{2a}}.} Each of the solutions given by the quadratic formula is called a root of the quadratic equation. Geometrically, these roots represent the x values at which any parabola, explicitly given as y = ax2 + bx + c, crosses the x-axis. As well as being a formula that will yield the zeros of any parabola, the quadratic formula will give the axis of symmetry of the parabola, and it can be used to immediately determine how many real zeros the quadratic equation has. The quadratic formula can be derived with a simple application of technique of completing the square.[1][2] For this reason, the derivation is sometimes left as an exercise for students, who can thus experience rediscovery of this important formula.[3][4] The explicit derivation is as follows.

Divide the quadratic equation by a, which is allowed because a is non-zero:

{\displaystyle x^{2}+{\frac {b}{a}}x+{\frac {c}{a}}=0.} x^{2}+{\frac {b}{a}}x+{\frac {c}{a}}=0. Subtract c / a from both sides of the equation, yielding:

{\displaystyle x^{2}+{\frac {b}{a}}x=-{\frac {c}{a}}.} x^{2}+{\frac {b}{a}}x=-{\frac {c}{a}}. The quadratic equation is now in a form to which the method of completing the square can be applied. Thus, add a constant to both sides of the equation such that the left hand side becomes a complete square.

{\displaystyle x^{2}+{\frac {b}{a}}x+\left({\frac {b}{2a}}\right)^{2}=-{\frac {c}{a}}+\left({\frac {b}{2a}}\right)^{2},} x^{2}+{\frac {b}{a}}x+\left({\frac {b}{2a}}\right)^{2}=-{\frac {c}{a}}+\left({\frac {b}{2a}}\right)^{2}, which produces:

{\displaystyle \left(x+{\frac {b}{2a}}\right)^{2}=-{\frac {c}{a}}+{\frac {b^{2}}{4a^{2}}}.} \left(x+{\frac {b}{2a}}\right)^{2}=-{\frac {c}{a}}+{\frac {b^{2}}{4a^{2}}}. Accordingly, after rearranging the terms on the right hand side to have a common denominator, we obtain:

{\displaystyle \left(x+{\frac {b}{2a}}\right)^{2}={\frac {b^{2}-4ac}{4a^{2}}}.} \left(x+{\frac {b}{2a}}\right)^{2}={\frac {b^{2}-4ac}{4a^{2}}}. The square has thus been completed. Taking the square root of both sides yields the following equation:

{\displaystyle x+{\frac {b}{2a}}=\pm {\frac {\sqrt {b^{2}-4ac\ }}{2a}}.} x+{\frac {b}{2a}}=\pm {\frac {\sqrt {b^{2}-4ac\ }}{2a}}. Isolating x gives the quadratic formula:

{\displaystyle x={\frac {-b\pm {\sqrt {b^{2}-4ac\ }}}{2a}}.} x={\frac {-b\pm {\sqrt {b^{2}-4ac\ }}}{2a}}. The plus-minus symbol "±" indicates that both

{\displaystyle x={\frac {-b+{\sqrt {b^{2}-4ac}}}{2a}}\quad {\text{and}}\quad x={\frac {-b-{\sqrt {b^{2}-4ac}}}{2a}}} x={\frac {-b+{\sqrt {b^{2}-4ac}}}{2a}}\quad {\text{and}}\quad x={\frac {-b-{\sqrt {b^{2}-4ac}}}{2a}} are solutions of the quadratic equation.[5] There are many alternatives of this derivation with minor differences, mostly concerning the manipulation of a.

Some sources, particularly older ones, use alternative parameterizations of the quadratic equation such as ax2 ? 2bx + c = 0[6] or ax2 + 2bx + c = 0,[7] where b has a magnitude one half of the more common one. These result in slightly different forms for the solution, but are otherwise equivalent.

A lesser known quadratic formula, as used in Muller's method, and which can be found from Vieta's formulas, provides the same roots via the equation:

{\displaystyle x={\frac {-2c}{b\mp {\sqrt {b^{2}-4ac}}}}.} {\displaystyle x={\frac {-2c}{b\mp {\sqrt {b^{2}-4ac}}}}.}

0
I did not ask about the formula but merely the bug i recieved while tweening. The answer is pointless and should be removed..... Zafirua 1348 — 5y
0
You copied and pasted this directly from the wiki as well. ScriptGuider 5640 — 5y
Ad