# Tag Info

37

Mathematically, a quaternion is a complex number with 4 dimension. But in game development, Quaternions are often used to describe a rotation in 3d space by encoding: a rotation axis (in form of a 3-dimensional vector) how far to turn around that axis Note that this information is encoded with sines and cosines inside the quaternion, so in general you ...

28

When working out the maths and solving for the Level conditional on experience XP, we obtain: Formula: Level = (1 + sqrt(1+8*XP/50))/2 Where sqrt() is the square root. For example, what is the player's level for XP = 300? (1 + sqrt(1+8*300/50))/2 = (1+7)/2 = Level 4 As requested. Or, what is the level for XP = 100000? (1 + sqrt(1+8*100000/50))/2 ...

22

The simple and generic solution, if you don't need to repeat this calculation millions of times per second (and if you do, you're probably doing something wrong), is just to use a loop: expLeft = playerExp level = 1 while level < levelCap and expLeft >= 0: expLeft = expLeft - expToAdvanceFrom(level) level = level + 1 if expLeft < 0: level ...

12

The question has been answered with code, but I think it should be answered with math. Someone might want to understand instead of just copy and paste. Your system is easily described by a recurrence relation: Which offers a nice simple closed form solution for XP: Which we can solve for Level: (truncate to integer, because the player needs all the ...

11

This is to add to @Philipp's answer. Also, what advantages do you gain using three points on a 2D plane? You don't really need quaternions if all you're interested is in rotating on the plane, i.e. about the z axis. In this case, all you need is the yaw angle, and you can exploit the fact that successive rotations about the z axis commute. So you can ...

9

Here's one approach to solving the problem using basic algebra. If you don't care about the steps, skip to the bottom. An easy thing to come up with is, given a level n, the total experience e needed to obtain that level: e = sum from k=1 to n of (t(k-1)) The t term stands for the increase in XP needed per level - 50, in the example. We can solve the ...

8

The point P to be transformed is, in homogenous coordinates: ( 50 ) ( 40 ) ( 1 ) The homogenous transformation matrix M is (using cos(pi/4) = sin(pi/4) = 0.7071): ( 0.7071 0.7071 -42.426 ) (-0.7071 0.7071 14.142 ) ( 0 0 1 ) noting that (40+20) * 0.7071 = 42.426 and (40-20) * 0.7071 = 14.142 and using the identity proved in my ...

6

This question would probably be better suited at StackOverflow. That being said: You are using the wrong modulo. Pseudocode: n = waveID % 5; n == 0 => Track3 n == 1 || n == 2 => Track1 n == 3 || n == 4 => Track2 If you use modulo you always have to use the size of you collection/repeating pattern (in this case 5). Furthermore I would recommend ...

4

I don't know enough haxe to make this code better, but I would probably just do var tracklist = [3, 1, 1, 2, 2]; gamePlayTrackId = tracklist[waveId % 5]; You can probably improve this by making tracklist static or any number of ways. I'm still learning though, so look at the comments before you implement anything.

4

A coder's guide to spline-based procedural geometry is a video from Unity event Unite 2015. In the video, the presenter gives visual explanation of how splines can be created and modified. Then, he goes on to give code examples for the same. Very informative. The video is for Unity3D, but the algorithms presented can be adapted to any platform.

3

As you will easily find out, the most straight-forward solution is to run multiple times an algorithm that checks whether there is an intersection between the segment formed by Point1 and Point2 (let's call them p1 and p2) and the ones formed by each of the vertices of the rectangle (let's call them r1, r2, r3 and r4). A clean implementation ...

3

Say, your circle is at 100, 120 and has radius 25. Say, your object is at x, y and has radius 9. So, the distance between the centers of the two is: sqrt((100 - x)^2 + (120 - y)^2) which means that the distance between their boundaries is d = sqrt((100 - x)^2 + (120 - y)^2) - 25 - 9 Now, if this distance is less than zero, we know that objects are ...

2

You're getting problems with higher numbers being multiples of more than one of the numbers you check. 6 is not just going to trip the last else, it will also trip the % 3 == 0 one. I might do it this way: StartGame() { m_musicLevel = 1; m_track = playGameplayMusic(1); } NextLevel() { m_musicLevel++; if(m_musicLevel > 5) { ...

2

Short answer: To store position, use a single vec3. To store rotation, use a quaternion and normalize it after every multiplication or after every n (1-1000) multiplications. You shall only use mat4s when it comes to drawing or transforming lots of vertices: Convert vec3+quaternion pair to mat4 and pass it to your shader or use it to transform vertices ...

2

If I understood what you're asking , you can start from Spherical coordinate system Very pseudo code to "list" a sphere from top to bottom: Let r be radius. Let PI = 3.14... Let's use degrees. For theta =0..180 For phi =0..360 List.add(PolarToCartesian(r,theta,phi)) Where PolarToCartesian: x=r * sin(toRad(theta)) * cos(toRad(phi)) y=r * ...

2

The way to "look around" in a 3d environment is to "rotate your camera". Your assumption to "move the objects around the camera" probably comes from the fact that when you render your scene, the MVP (model-view-projection) matrix stack transforms all your objects. Human beings like to think in what they figure out. And their world is in 3d, and when they ...

2

This is the concept: You add "rotation movement" and "linear movement" together, and you get "rolling movement". Once you calculated all vectors for rotation movement, then you can simply add linear vectors to your results.

2

You seem to have taken the image on Wikipedia, on the bilinear interpolation page. The legend of that image says [...] the green dot is the point at which we want to interpolate. So the P is at first a point from which we want to find the value. You submit a set of coordinates to the interpolation function (x, y), and it spits you a scalar (a single ...

2

All the math involved here is very important to know for all sorts of reasons, some of them applicable to game development. BUT This is a game development site, not a math site. So let's discuss how these things work not as algorithmic series, but as sets, because that is the sort of math that applies to leveling in games you might actually develop to ...

1

I suspect the method actually used doesn't actually rely on parallel projection and it only seems so through the approximation of the article writer and subsequent translation. The problem with bringing a parallel projection into this is you'll attenuate perspective, which is not what you may want. At any rate the method I describe here achieves the same ...

1

So firstly, I'd like to apologize if my question was poorly worded or if it was just confusing in general. I think I've figured out the proper solution now. It took a while because I had passed it off earlier after trying it and not immediately seeing desired results (I needed to basically remake my wooden manikin object from scratch). Basically, I found ...

1

The robust solution is to build a frustum of planes symbolising the camera and check the plane against all of them. The first part involves creating the frustum which can be a bit tricky if you're lacking in basic linear algebra; Start with transposing the matrix you're using to transform from worldspace to projected space, the reason for this is because ...

1

You could try something like this int hp = 15; for(int i = 0; i < hp/2; i++) System.out.println("Heart"); if(hp % 2 == 1) System.out.println("Half Heart"); Just replace the print calls with your graphics calls.

1

the page where you probably get that image states : "The four red dots show the data points and the green dot is the point at which we want to interpolate." So, you know the values at Q12,Q22,Q11,Q21 , and yoi want interpolate the value at point P

1

If I understood what you're asking ,after you get your toEdge point , you need Intersection of a Line and a Rectangle to get intersection point. Then calculte distance from start point to intersection point.

1

Based on you comments, it seems that you're storing the orientation of the object as a set of Euler angles, and in/decrementing the angles when the player rotates the object. That is, you have something like this pseudocode: // in player input handling: if (axis == AXIS_X) object.angleX += dir; else if (axis == AXIS_Y) object.angleY += dir; else if (axis ...

1

If your levels are procedural / infinite, then the using the chosen method is good. If you have a limited set of levels (i.e., only 10), then just associate the track choice with the level, hard-coded or preferably stored in the data that is loaded per level.

1

You need to combine a modulo (for the wrap-around) and a division (for the duplication of tracks). With some testing I got to: static function track(level:Int):Int { return Math.ceil(((level - 1) % 5 + 1) / 2); } (live example on Try Haxe) The idea is to divide a wrap-around, adjusting for no zeros. There might be a way to simplify this though.

1

I've done this before. The easiest method is to simulate the projectile, record points along its trajectory and note the closest point to the target. What I then do is get the target's location + (target velocity * time taken to reach closest point*) to get the location it would be by the time the projectile reached it. All you need to do then is Math.atan2 ...

Only top voted, non community-wiki answers of a minimum length are eligible