# Tag Info

1

First use Zehelvion answer to make the car turn correctly, then: Use the timestamp, you measure how much time it took for your last iteration and use that to modulate the speed at which you are changing things. void RunGame(float deltatime) { if (key.KeyCode == Keys.Up) { Player1.speed += accelaration * deltatime Player1.speed = ...

5

Start by adding a variable for the angle that the car is moving at. float angle = Math.Pi / 2; Then add a variable for the current speed. float speed = 0.0; Now create three constants: public static final float acceleration = 0.1; public static final float maxSpeed = 5.0; public static final float rotationRate = Math.Pi / 50; For starters, get your ...

12

L-Systems, from what I can tell*, are a set of grammar-like substitution rules that you can apply recursively to get interesting, "organic" results. Plants are where L-Systems are often used, as they show a lot of recursive growth (i.e. branch splits off into more branches). For a simple example, I'll show a "lollipop" tree generated using an L-System: ...

7

The short answer: Using one big texture will probably be faster and should defiantly not be slower than multiple small textures and here is why: After taking a look at the SDL source code i can see that SDL suports a bunch of renderers (opengl, gles2, psp, d3d ...) and (except the software one) all of them are implemented in the same fasion: 1:BindTexture, ...

3

Because this game is 2D and I doubt you'd hit the limit of VRAM and unless you are swapping through thousands of textures, I don't think it makes much difference. There are benefits and drawbacks to both: Packed textures are easier to manage and can be smaller on disk (potentially in VRAM) however require math to extract the correct sub texture. ...

0

It's called a Hash data structure aka an associative array. It is often used to represent a sparse array. For instance like in your case, a huge world with myriads of tiles, that is sparsely occupied by only hundreds or thousands of units. It is very fast because it knows where to look for values (in your case units) with a certain key (in your case ...

3

There are a multitude of 3D projections out there with different properties and any 3D modelling tool worth its salt ought to be able to configure the cameras to achieve those looks. A perspective projection like the one you have used have diminishing widths and heights as you go further away, which will result in the trapezoid shape that you illustrate. ...

1

Getting null reference exception is normal since they were created in the previous scene and destroyed in the current one. To move them to the next scene, you need to call DontDestroyOnLoad. Why don't you create your assets after the scene is loaded? GameManager should be responsible for creating player and enemy objects and keep track of the game state. In ...

2

Take an arrow image without any perspective Rotate the image by the desired amount of degree Scale the image vertically.

0

I've found a solution: public void Draw(SpriteBatch spriteBatch) { //Interpreting tiles as bounds //Sub-ing and add-ing 128 just to get more tiles than visible, //so the world feels like more alive // 16 - is tile size // 128 / 16 = 8 more tiles int startX = (va.area.Left - 128) / 16; int endX = ...

0

I had similar issue, but my character stopped at some points. After adjusting rigidbody mass and physics material friction, it worked. Maybe it will work in your case.

0

This is my way for achieving this effect: void OnTriggerStay2D(Collider2D other) { Debug.Log("Object is in trigger"); player.rigidbody2D.AddForce (-Vector2.right*20000*Time.deltaTime); }

4

The sign of the dot-product of C with AB will be positive when the vector component of CD parallel to vector AB is in the direction AB, and negative when it is in the direction BA. The sign of the (z-component of the) cross-product of vector CD with vector AB will indicate which side of AB the agent is approaching from. Depending on your sign conventions, ...

2

If I understand what you're asking, the vector CD is just a vector, not a ray, so only the direction matters, not location. However, AB is a line segment, not just a vector, so its location matters. Your tests have one 'if' test to make two cases, but I think you actually have four cases. Let's look at the diagram in AB's reference frame: If you can ...

0

You have both the current position and the last position on move. (touch.position, leftFingerPos) You can do a ray cast using these to see if there is a collision with your arrow. http://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html

2

I don't have a specific example for an Isometric camera, but it sounds like you are asking about the basic camera system in general. The camera I use in my games is somewhat simple and is illustrated in the figure below: The Camera class contains the following member variables: Vector2 position; Vector2 viewport; Rectangle worldRectangle; Converting ...

5

You're on the right track. I would start by determining the player's direction based on the keyboard state: direction = Vector(0, 0) if up pressed: direction = direction + Vector(0, -1) if down pressed: direction = direction + Vector(0, 1) if left pressed: direction = direction + Vector(-1, 0) if right pressed: direction = direction + ...

1

You need to remember that C++ is a multi-paradigmatic (OOP, functional, procedural, ..) language and you should use the programming paradigm that best solves your current issue. OOP doesn't lend itself well to this problem. In OOP you think about single objects in isolation (concept of "a tile"). But most of your algorithms will operate on a whole ...

1

I would advise against using inheritance to manage different tiles. Imagine how annoying it would be having to define a new class every time you add seemingly different types of tiles. That would result in a lot of implementations for simple things like a grass or a dirt tile. It is much simpler and more maintainable to make tiles configurable. Define a Tile ...

0

(I cannot comment so I'm answering) If you build an array with reference for the types of the files (I don't know much of C++, so I'll pseudocode) tiles[0,0] = ref_to_fire_tile tiles[0,1] = ref_to_fire_tile tiles[0,2] = ref_to_grass_tile ... Where ref_to_*_tile holds a reference for a specific type of tile which inherits from a generic one, this way ...

6

It is fine to have lots of instances. An instance of a class without virtual methods is just like a POD C struct in terms of memory consumption which is similar to primitive data types. It is no problem. Your concern when instantiating many instances of a class are resource related I would think. CPU - should not be affected because you will be ...

0

To give an example to my comment public class Tile { //some variable stuff; public Tile() { //some constructor stuff; } } public class FireTile { //some variable stuff; public FireTile : Tile() { //sets player on fire //some constructor stuff ...

1

Yes, this is a fine approach - it will be orders of magnitude faster than creating a primitive per data point. Assuming single-channel data, you should use whatever DXGI_FORMAT (or equivalent in OGL) maps to your source data, and convert in the pixel shader. There are native types for 8, 16, and 32-bit integers, as well as 32-bit floats. You should also ...

1

Your best bet is to attach the debugger and see where things are going wrong. If you're getting a stackoverflow it means you're recursing too far into your CheckSquare method. That either means your map is too large, or you're checking the same tiles multiple times. I'd bet on the latter given your screenshot. Depending on the IDE you're using, you can ...

6

A typical implementation of A* will use a loop instead of recursion. Change the if (ClosedList[ClosedList.Count - 1] != End) CheckSquare(...) into a while loop. However, I suspect the code won't work correctly even with that change, because you're clearing all the data after you check just one square. A* needs all that data (OpenList, gValues, etc.) so you ...

0

Anyway, any advice? How could I make attacking and moving feel more natural? What about the hit mechanics themselves? My biggest gripe right now is: I don't think "Pick an enemy in a small circular area ahead of the player" is really good. What should I do? You could have the hit detection and movement restrictions match your attack animations. If ...

0

Creating an horizontal or vertical gradient is very simple. Anything else is going to be a little more complicated. If you are looking to strictly create an horizontal or vertical gradient, you can do it as follows. This will create a RenderTarget for a horizontal gradient: //create a blank 1x1 white texture Texture2D BlankTexture = new ...

1

If you are doing a classic 2d platformer (which you [the OP] are not [this answer is directed at people who are doing it]) then you could use something like DragonBones (open source). Even in your situation, you could make some considerations and implement something like this. If you must have the tool look perfect from a lot of angles and can't compromise ...

0

I made my inventory work with an "Item" class that ties actual game objects to their icon, description, etc. - the inventory only deals with "Items" while using an item (placing it, for example, in the game world) would consume one and then create the game object. I know that's a bit simplistic of an answer, but I felt like sharing my two cents.

0

I assume your noise is outputting height values for the terrain - the style shouldn't matter, as that's applied after the noise is done with. Add a lower octave of noise and add (or otherwise combine) them together. The lower the octave (larger amplitude and lower frequency) the larger/longer the features it creates, so to add hills you need to add that sort ...

0

I'd highly suggest you look into implementing a Quadtree. This would allow you to run a query to fetch all the objects in your viewport, as opposed to checking every single entity before a draw. Have a look at the following sample query code: List<Entity> entitiesOnScreen; entitiesOnScreen = QuadTree.GetObjects(Viewport.Rectangle); foreach ...

0

1) You don't need to calculate the visible objects in a single frame, you may use a bit bigger viewport, and calcultate only 500 objects per frame, if you have 20000 objects and your framerate is 50fps, in 40 frames you will have the right list, and it will take 0.8 secs 2) if your objects are not very complex or are static, sometimes is faster to put them ...

0

You would likely have to switch over to the 3D (lower level) rendering and then use instancing which offloads most of the work to the GPU. http://www.float4x4.net/index.php/2011/07/hardware-instancing-for-pc-in-xna-4-with-textures/

1

Invisible: Don't add any components that render to the screen, i.e. mesh renderer, sprite renderer, line renderer, etc. Collidable: Add a physics collider to the object and set the bounds how you like. Non-solid: Make the collider a trigger. Triggers will trigger a collision event, but won't have a collision response, essentially making them non-solid ...

0

To help you with collision : There are ways to check for pixels changing color(being drawn over eachother) but I don't use that. I give all object in the game a Bounds Property. The Bounds is a Rectangle that is at the position of the object(enemy/character). Rectangles have a method .Intersects that allows you to see if two rectangle are intersecting. ...

1

You could Create one Sprite Card Object. Give it the the four suit textures, face card textures, and card background texture. Example : for the 7 of spades you would draw the spade texture at 7 different locations with a white texture of a card in the background, and use DrawString to Draw the 7. That way you could (in your game class) say Card card = new ...

2

[EDIT] As your question, now clearer seems to be more about design and not so much a technical question I change my answer a bit. Your first attempt was the right one. Your sprite contains a drag&drop component. But it's necessary that it also contains the prefab it will instantiate once dropped in the game world. The main design is, from an inventory ...

0

I wouldn't use any permanent collision box that's moved around or anything similar. Instead, just play the attack animation and pick one specific frame where you're looking for collisions inside a specific area. Since I assume the overall attack animation will be rather short/fast, there shouldn't be any way to notice any difference. For example, the ...

0

After experimenting with my code for like 3 hours, I found the solution myself:- Before going to a different state, use the input.clearKeyPressedRecord() to clear all previously recorded key-Presses, or else even after changing a state, previously stored keyPress event will cause problems. So instead of doing this, public void changeState(GameContainer ...

3

Rigidbodies can be said to operate in two modes: Non-Kinematic has physics driven movement, the physics engine will consider any forces brought to bear on the object to calculate and apply changes to velocity, rotation and position. Kinematic lacks physics driven movement, the physics engine will not cause this object to move and any forces on the object ...

1

yeah, all solutions have already been made... i'll just add some more code (i'm rather from stackoverflow ^^) assuming you're using bounding box assuming you use plain java (java.awt) . List<Shape> shapeList = ...; //you know where you get them Shape exampleShape = shapeList.get(0); Rectangle2D boundingBox = exampleShape.getBounds2D(); see ...

0

You can use a simple shader for this, but I wouldn't do so, simply due to the fact that you're doing simple tinting with one color (or shades of one color) only. The Unity script above would work with some modifications, but you'll have to keep in mind that there's additional overhead/metadata in there that doesn't belong to the actual GLSL code. What I'd ...

0

To answer your question directly, it is possible to set the scene/game windows to enable gismos for your colliders but they will only be displayed when that gameobject (or a parent) is selected in the hierarchy. This can be improved by attaching a script that implements OnDrawGizmos(), as an example here is an implementation that would visualize a ...

1

If you know the canvas is a rectangle then this simplifies to the case of checking if the bounding rectangle of the shape being drawn is contained within the canvas' rectangle. That's a fairly efficient check to run, and (generally) finding the bounding rectangle for your shape should be fairly easy (just finding the minimum and maximum x and y coordinates) ...

0

I found the solution, I had to change this line: glm::mat4 MVP = Model * ViewProj; To this line glm::mat4 MVP = ViewProj * Model; I made some research and it seems that in DirectX its the other way around.

3

As already pointed out in the comments and answer: This can be arbitrarily complex. Particularly, depending on the exact use case and performance requirements, you can employ some rather sophisticated data structures in order to make these tests fast. The bounding box test is the simplest one that should be done in any case (and in fact, could already be ...

3

A few things catch my attention off the bat. First: filedata = sr.text.Split('\n').Select(s=>s.Split(',').ToList()).ToList(); Feels highly dubious to me. Are you sure this is doing what you expect it do be doing? Second: float halfWidth = mainCamera.aspect * (mainCamera.orthographicSize/100); float tempYOffset = ...

5

I have good news and bad news for you: The Bad News: I don't know or remember any Java library that does what you want The Good News: It's really easy to implement this type of algorithm yourself! Here's a couple, you can mix them to optimize your collision detection depending on the type of shape. BB Collision Detection You can imagine a box around ...

0

[EDIT: as I don't know what lib you're using, and as this question is not specific to Java, my answer is in pseudo-code.] If I understand your question correctly, atan2 is not what you're looking for. What you want to achieve is moving something (which has coordinates) from one point to another according to time. You just need to compute the vector between ...

0

Suppose the projectiles curret position is $(x,z)$. Then, in each step, you let $x_{new} = x_{old} + t \cos(\theta)$ and $y_{new} = y_{old} + t \sin(\theta)$ where $\theta$ is the angle you found, and $t$ is some small number (depending on the number of milliseconds since last update, for example).

Top 50 recent answers are included