Tag Info

New answers tagged

2

I will explain it line by line: var time = new Date().getTime() * 0.002; new Date().getTime() returns the current time in milliseconds (1 second = 1000 milliseconds). This is multiplied by 0.002 to scale the time -- slow it down, in this case. var x = Math.sin( time ) * 192 + 256; Scaling down the time is important, because it is used in this ...


1

Short answer: by smart compositing rotation and translation. In the image below you can see the process (radius r is distance of your planet from star). If you rotate the moon by rot_m degrees(updated in main loop), it will circle the origin point. If you first rotate and then translate by radius r it will circle in right distance but wont follow your ...


1

I posted recently a response to a similar question http://stackoverflow.com/questions/24231389/struct-or-class-for-matrix-4x4-object Basically valuetypes are the way to go for storing matrices, more benefits than downsides. You may also organize a matrix to be more GPU friendly by transposing the fields directly into the matrix struct (SharpDX is not doing ...


0

You could also achieve this in a "dumb" cycle, it is not optimal but will work. Simply keep adding any block next to the current that is inside the area. Lets say you would like a list of the blocks: Rectangle area = new Rectangle(A.x, Math.Max(B.y,B.x), A.y, Math.Min(B.y,B.x)); List<Block> blocks = new List<Block>(); Queue<Block> ...


-1

Is this in 2d? For 2d: The position of the block you place is {Sin(theta),Cos(theta)} = {x,y}. So at 90degrees, your position will only move in the x-axis by one block each time. The rotation of each block should be the same theta as well.


0

The proper way to make this 'knockback' movement is by applying an impulse on the knocked object. The impulse will be in the direction of the velocity of the hitting entity (the projectile), scaled to some number that fits your game (that should probably take into account the masses of the two objects). To make the entity slow down gradually after the hit ...


1

First code, code the normal movement of the character to progress a constant distance toward the target position every frame (ie. inside the Update() function). Then put that movement code inside an if statement for if the character is being knocked back. Only move toward the target if not being knocked back. If being knocked back, move toward the ...


1

This formula updates value so a constant fraction of the difference from the value and the target is removed each frame. Let alpha = 1/(someFactor+1). Then we can rewrite updating to the new value' as: value' = (1-alpha) * value + alpha * target Then basic algebra says value' - target = (1-alpha) * value + alpha * target - target value' - target = ...


0

I'm assuming that you're incrementing someFactor every frame, yes? someFactor += 0.1f; Why not try incrementing it based on dt? someFactor += 0.1f * dt; This concept is reified in Jason Gregory's Game Engine Architecture under Section 7.4. if you're interested in reading into it further.


1

I believe I know why it's behaving strangely. Here's a diagram I drew conceptually demonstrating the problem: I would solve the math for you too, but it should be easy enough from here. Give it a try and if you get stuck, just comment and ask.


4

Let me try to give you something somewhere between The Light Spark's answer and Elliot's answer, because from what I read, you're really looking for an algorithm to follow and not just math tossed at you. Problem Statement: Given that you have a location A (50, 50) and a heading (since you didn't provide one, I'll assert it as y = 2 * x + 25), find where B ...


5

I've done this with trigonometry rather than matrixes in the past (I am a matrix noob). Ashes999's answer is halfway there, get the relative vector, then rotate that by the inverse of EntityA's angle. relativeX = B.x - A.x relativeY = B.y - A.y rotatedX = Cos(-Angle) * relativeX - Sin(-Angle) * relativeY rotatedY = Cos(-Angle) * relativeY + ...


0

Figured it out mostly thanks to http://gamedeveloperjourney.blogspot.com/2009/04/point-plane-collision-detection.html Made me realize I had to verify the normal a bit closer, turns out my plane's grid was being rendered a little different than the actual coordinates for the verticles. No wonder this was so hard to get right! The pixel was projected ...


11

Okay, so Assuming that you know what the World Transformation matrix for that object A is, You just need to construct the inverse of that matrix and you will have what you need. Suppose the rotation, scaling and translation matrices of object A used to get it to Global Space are R, S and T respectively. You will multiply these together like S * R * T = W ...


-1

To put it simply entity B would need a reference to entity A. You'd then need to get the difference between entity's A position and entity B's position.


4

I'll assume that the A, B, C, D points really do lie on the same plane, i.e. that the two triangles form a single flat surface. The first step is to calculate the plane equation for the plane. If you don't know what that is, don't worry too much about it. It's a set of four numbers that specify the plane's location and orientation in space. It can be ...


0

This seems like a 2D view in which case it should be feasible to project the entity's rendered size at 100% scaling, then figure out the ratio of that value to the total viewport size and go from there.


0

I assume that we're in 2D, and by intersection points you mean the points where an edge of one OBB touches an edge of the other. SAT won't give you those points, but you can easily find them with a simple line segment intersection test (such as the one in this SO answer), applied to each pair of edges. There are 16 such pairs, so it's not a huge amount of ...



Top 50 recent answers are included