Tag Info

Hot answers tagged

17

I haven't looked at specific implementation of A* by Aaron but with a normal A* you could include the 'block tower' as passable terrain but update the heuristic so that the 'cost' is much higher than a normal tile (so that AI will evaluate whether it is easier to destroy the block and continue or simple go around via the path that is not blocked). Then you ...


9

Ok, that's awkward. My last edit revealed the answer to my problem (that I've been struggling with all day): QGraphicsView casts the camera x/y position to integers... This is the solution: void SceneView::centerOn(const QPointF &pos) { if (mScene) { mScene->setX(int(-(pos.x() - width() / 2))); mScene->setY(int(-(pos.y() - ...


4

You can do this via masking on the cpu if you prefer to not use shaders yet. You'll need these resources: Spaceship texture (no shield visible, left) Shield texture (only the shield visible, needs to fit the ship, middle) Empty editable Texture (pixmap) that you can draw onto (same size as shield texture, right) Point of impact You can draw your ship ...


4

I'm using Hooke's Law here as the definition of a spring. () Given the derivatives of position and velocity, are velocity and force respectively, we can construct a differential equation for the stretching of the spring. Which is just a damped harmonic oscillator, and since we already know that only the under-damped case need analysis, we can obtain a ...


4

You are right in your assumptions of what needs to be done! In physics engines, after a collision was detected but before the collision is resolved (The changing of the objects velocity) there are a few steps which need to be done. One of these steps is what I call decoupling: The process of separating two intersecting objects. This is the stage you are at. ...


3

You could draw this using a multiply blendstate. BlendState multiplyblend = new BlendState(); multiplyblend.ColorBlendFunction = BlendFunction.Add; multiplyblend.ColorSourceBlend = Blend.DestinationColor; multiplyblend.ColorDestinationBlend = Blend.Zero; Create a bitmap of a white circle in a black background (mask). The white is the part of the shield ...


3

You can attach the sprite to the child of the main game object which handles the collision detection logic. Whenever you want to flip the sprite just do it on the child object leaving the main object as it is. This way you can achieve your desired result :)


2

One way to apply light effects with the Context2D is to use the composite operation 'lighter' (globalCompositeOperation='ligther'), and adjust the alpha (globalAlpha= 0.0 to 1.0). Then you can either : • Draw the shape of the light with several geometric drawings that create a simple shade to get a cartoonish light effect. • Define gradients to get a ...


2

You need to flip the texture, not the object. Sprite/Plane meshes are one-sided so if you flip the actual object, you are seeing the back of it, which is transparent. Edit: You could also make your mesh two-sided. But Unity doesn't provide a flat, 2-sided rectangle. You will have to make it, either in a modelling program or with code.


2

When the user presses the "orbit" button, store the vector between the ship and the planet. On every update, change the vector's angle leaving magnitude the same and then update the ships position by adding the planets position and the vector pointing at the ships new position. This will create the effect of the ship moving in a uniform circle around the ...


1

You need to create a vector pointing towards the mouse -> Subtract the position of your cannon from the position of your mouse. vector2 dir = mouse.position-cannon.position Then you get the angle from this vector by using this formula if y is up and x is right angle = arctan(dir.y/dir.x) // or use atan2(y,x) Now you have the total angle that you need ...


1

If the sprites are in your Assets/Resources directory, you can load them programmatically as follows: Sprite[] spriteSheetSprites = Resources.LoadAll<Sprite>("spriteSheetName); This will yield a Sprite array containing all of the sprites from your spritesheet, indexed by their order on the sheet. A requirement to use this is that the image's ...


1

I was playing around a little and rereading the manual again. It noted that the size of the actual box is 2x the given size. Half-widths. So I continued to play around inside my graphics system and continued to see where the box was colliding and not and ended up with: Negate the (untouched) size from the position. Double the size of the boxes. glm::vec2 ...


1

Euclidean distante = sqrt (dx * dx + dy * dy), for your distance you need to define dx as min(abs(x2-x1),screenwidth-abs(x2-x1)) same thing for dy. Usualy the direction vector is Pt - Pm (Position vector target - Position vector missile). In your case you can define Direction vector x component as if (x2-x1)>=0 if (abs(x2-x1) < ...


1

my approach will be almost similar but I will prefer to use a full sprite sheet of cards to avoid the extra naming problems. Before we get started here is the link to the sprite sheet. http://i.stack.imgur.com/gnv4Q.jpg We need to create one script named Card which can hold its value and type. It should look like this:- using UnityEngine; using ...


1

try using GameObject.FindGameObjectsWithTag or GameObject.FindWithTag or by name (or namepath) GameObject.Find bool playerexists = (GameObject.Find("player") != null)


1

In my opinion the best is start with a good AI layer that uses a state machine approach (here and here). Making it simple, the current state AI evaluate some inputs, make a decision and eventualy jumps to a new state. The movement and animation layer relay on actual AI state to do their stuff


1

I'm not sure I completely understand what you are asking, as it's hard to tell what you mean by your "game style", but I will say that a path-finding algorithm is not necessarily overkill, especially if you would like your NPC's to find specific routes around obstacles. From my own experience with AI navigation, there are a couple of very popular types of ...


1

I'm not experienced programmer, but as for me, I try to divide as much logical parts as I can into different scripts. For ex, for the character you can use something like MVC, model-view-controller pattern. The point is that one script processes user input and communicates with tho other parts which are responsible for animations and actual movement. In ...


1

To determine the cone you should create some variables like AttackLength, FieldOfViewAngke and get enemy component to determine enemy position lookDirection = enemyPosition - player.transform.position; lookDirection.y = 0; attackDirection = Vector3.zero; float angle = Vector3.Angle(lookDirection, transform.forward); if (Physics.Raycast(enemyPosition, ...


1

Hey there are couple of things which you are missing out. 1) Even thought the motion is in 2d plane but the gameobject dimension is 3D, so use Vector3 instead of Vector2 2) When you calculate Vector3 Movetowards it returns a value which is calculated upon current position , target position and speed. This needs to be assigned to the transform of the AI. ...


1

Make sure that "Is Kinematic" option for rigidbody in the inspector is off. Here is a very basic example for adding torque. var torque: float; var rigidBody: Rigidbody2D; function Start() { torque = 20; rigidBody = GetComponent.<Rigidbody2D>(); } function FixedUpdate() { rigidBody.AddTorque(Time.deltaTime*torque); } Time.delta time ...


1

As Vector2 is a type composed by two numbers which are x and y, then you should be able to get the position by asking both numbers: Vector2 YourVar; YourVar.x; YourVar.y; So you should use something like: SetPositionToMove(YourVar.x,YourVar.y); //if the functions expect x and y or: SetPositionToMove(Point2(YourVar.x,YourVar.y)); //if it expects a ...


1

Its actually very similar to the way it is done in XNA , only a few changes in the syntax and loading approach. Here is the most basic way in which it can be done. You can build on top of it as per your needs. Before we start, we need to make some tile prefabs and store it inside the resources folder. Lets define some variables, and initialise them some ...


1

here you go, here is a implantation of the A* in Action script 3, i wrote this a few years ago, there are a few things such as grid, grid view and node classes that i'm using which really don't have anything to do with the A* algorithm itself, and are all used for the graphic and visual side of the work, still if you are interested i can put them here so you ...


1

modify a* considering goal as a set of points instead of a single point. If the euristic function is the distance, the each step of a* chose the path that minimize the closest point distance. Check also this


1

i did something similar a while back, it's not that hard, one very easy and understandable way is : 1- rotate everything! means every line every object, so everything is simply flat! 2- calculate velocity, gravity, friction and ... anything you like ! just the way you always do in a flat and without rotation world 3- rotate everything back the way it was ! ...


1

You could re-order your std::vector<Object> by creating a function that sort it by Y position of your objects void SortObjects() { std::sort(Object.begin(), Object.end(), CompareYAxis); } bool CompareYAxis(const Object first, const Object second) { //Do the comparison here } I think this would work.


1

No. Not at least from what you're describing. An AI that's unique to one animal that takes into account all of the variables of such a complex environment would be taxing to simulate just on it's own. Plant life would be easier, but the cost to simulate all the plants would add up fast. A continuous simulation of the entire ecosystem would be virtually ...


1

I would forget right away the option to create the sprites in order based on their y coordinate as it will create a hell for you because it's not a flexible design. You look like you need a common way to handle the drawing process. You can achieve this using polymorphism. I would probably create a IDrawable interface, which requires children to have ...



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