# Tag Info

37

The general approach to handling this in classic Win32 programming is to capture the mouse delta each frame, and then reset the mouse position to the center of the screen. You also want to make the mouse cursor invisible, obviously, as otherwise things look ugly. You can do the same thing in XNA, you just work with a slightly different interface. So you ...

18

I went to a GDC session this year presented by the guys at sucker punch, discussing how they handled assisted aim and movement for inFamous. My understanding is that Halo uses a very similar system for assisted aiming, and here's the basics: When you hit a button to fire, the shot should always go directly where the reticle is pointing. Otherwise, players ...

17

First you need to determine the difference in angle between the turret facing direction and the direction to the target. Vector2 turretToTarget = target.position - turret.position; float desiredAngle = atan2(turretToTarget.y, turretToTarget.x); float angleDiff = desiredAngle - turret.angle; // Normalize angle to [-PI,PI] range. This ensures that the turret ...

11

In a tower defence game I made, I used a quadratic equation to predict the intersection and thus aim point. The following aiming code snippet assumes the enemy is traveling at a constant speed and direction. It also assumes the projectile will be traveling at a known constant speed (could be any speeds but must be known to the algorithm). Vector totarget = ...

11

I'll answer with an autobiography. Projector sheets You know those ancient projectors that come with transparent sheets? In primary school, I discovered you could draw a character's torso on one transparent sheet... ... and then take out another sheet, lay it on top, and draw arm with a gun on it ... ... and then rotate the top sheet with the arm on ...

10

Random thoughts (no code)... In real life, one targets a vehicle with complex movement by trying to figure out what that movement is so as to anticipate it. If you are writing code for AI to target AI, then you should create a targeting AI that is derived from the target AI. For example, if your target will run for cover if near by, the targeting AI ...

10

To do this in XNA, you will need to use a shader. You will need to render your scene to a texture (Or, render just the portion the cursor covers), and then draw the cursor using that texture and a shader that inverts the color. Unless you've already got a deferred renderer, this will probably be more hassle than it's worth. If you do, you can use the ...

10

There is no need to break it down into 2 2d functions. That quadratic equation you are working with works fine in 3d as well. Here is pseudo code for either 2d or 3d. It implies a tower (tower defense) is shooting the projectile: Vector totarget = target.position - tower.position; float a = Vector.Dot(target.velocity, target.velocity) - (bullet.velocity *...

8

If you're going to ask the user to aim up and down, you need the player to be able to judge those up and down distances. With a static top-down camera, that is virtually impossible, and grossly unfair of you to demand of the player, no matter how you map it to controls. If you're set on using a top-down camera, then your player character should handle ...

8

There are good answers here. I had to figure it out for myself on the project I'm on, but came to the same conclusions as the Sucker Punch guys (and I had thought I came up with something novel. Baww :( ). I find it useful to consider your entire first person 360x180 degree "panorama" as an "acceleration field". All valid targets create gravity wells which ...

6

This " answer " is to add some visual information to the answers already given. 2: We first create a vector ( 2D in this case with component x and y ) by taking the difference from both positions ( mouse - player ). 3: We then Normalize it to create a so called " unit vector ". Which means to bring the length of our vector to 1. This is done by ...

5

Okay, let's put some sanity into this. I am afraid you are not making it easy at all, your code does not compile, is inconsistent with regards to variable names (playerVelocityX becomes playerXvelocity after a few lines? what is xVelocity?) and is too verbose. It is basically impossible to debug lest you put considerable effort into it. So, here are the ...

5

This question on GameDev, and this question on StackOverflow should provide you with the answer you're looking for. :)

4

A system like this, with multiple bodies, is going to be chaotic. I don't think that you would be able to solve an equation for it in real-time. The best you can hope is to find a solution using a genetic algorithm; 1: produce a number (e.g.100) of random solutions (angle, power pairs). 2: simulate these solutions. 3: if any of these, end up hitting the ...

3

You are trying to fire an arrow from point a(player) to b(mouse position) in 2d space? you can simply do the following formula to get the direction. (rather than degree) v1 = ( Player.x, Player.y ); v2 = ( Mouse.x, Mouse.y ); dir = v2 - v1; dir.normalize(); arrow.xy += dir * speed; hope this helps you achive what you want.

3

I'm not gonna give you an answer I'm sure is useful or even correct, but here it goes: After playing with mathematica a little more (check the end of the answer for notebook /published notebook) files, this solution appears to be correct, even thought it might not be the best one in terms of efficiency. I wrote this in mathematica which corresponds to your ...

3

What you're probably looking for here is a PID Controller, similar to the answer accepted on this SO question I had initially answered that question by "rolling my own" but this answer is significantly more complete and elegant.

3

For input to feel good on consoles you will want to have some processing done to it. First we converted the linear input that comes from the analogue sticks into a curve that gives us more sensitivity around the stick center and less sensitivity at the borders. This can be done with small tools that help you create and visualize these curves and spit out ...

3

What you have here is a basic control problem. The turret is the system, the acceleration is the control and the sensor measures position/velocity. There are many ways of tackling these problems, as it's a very well-studied problem in engineering. Key is ending up with a stable system, i.e. a system that does not generate oscillations. This is usually done ...

3

After testing a few ideas, I'm focusing on this answer because it is the cleanest code. The algorithm is very similar to your approximation, except I've modified it to iterate to a given accuracy: double max_error = 0.0000000001; // measured in radians double dx=targetPlayer.XCoordinate - myPlayer.XCoordinate; double dy=targetPlayer.YCoordinate - myPlayer....

3

This can be achieved using trigonometry and vector mathematics. First, calculate the direction (or normalized vector) that the turret should face: Where a is the target vector subtracted by the turret position: direction = Vector2.Direction(targetPos - turretPos); Assign this value to a Vector2 direction inside your bullet class. You should to ...

2

Field of view (FOV) plays a big part in game feel for first person shooters on all platforms. Standard horizontal FOV in first person shooters tend to range between 90 degrees to 120 degrees. However, PC and console players sit at different distances from their screens. A 90 degree FOV may be fine for a 30" screen 5 feet away from a console player, but may ...

2

The biggest effect on the PC will be input latency and framerate. Here is an article on the subject

2

The AI, the target's location during the time the projectile is fired, and the target's eventual location at point of death form a triangle.Here is what you should already know: Side length a, which is the projectile speed Side length b, which is the target speed The angle of motion of the target of motion of the target. You have three parts of the ...

2

Use storyboards and blocked out animations to preview game play changes, both are easy to create and cheap to modify until you arrive at a solution. Movie studios call this "prefiz" and use it to save money and effort. You can animate several new viewpoints in a day and save a week of coding.

2

Having a moving shooter is identical to having a stationary shooter. Simply subtract the shooters movement vector from the targets movement vector. Target [-5,0] Shooter [4,1] Target - Shooter = [-5,0] - [4,1] = [-9,-1] Calculate the firing vector/initial angle, then add the targets movement vector to the bullet like normal.

2

The ratio of the horizontal to the vertical component of the vector is proportional to the ratio of the horizontal and vertical difference in position. The proportion factor is the speed divide by the direct distance (calculated by the pythagorean theorem). distance.x = target.x - start.x; distance.y = target.y - start.y; distance_direct = ...

2

As Almo's comment mentions, your last paragraph is a pretty solid approach to the problem. If you'd like one that requires less calculation however, another solution (provided you already have a method to hit a stationary target with a mortar shell) is to launch at and store the target's position in the world. Then, while the shell is in the air, make ...

2

Doubt I need to take into account that 10 milliseconds per game update, since when I don't move I never use 10 milliseconds and it works perfect. I think that's where you're mistaken. The fact is you say you do still miss 1% of the time when not moving. This miss rate results from a combination of the incident angle, distance, speed of shot relative to ...

2

You could treat the turret as stationary and subtract the velocity of the turret to the target's velocity before the start of the code, provided it works for a motionless turret. To subtract velocity vectors, if the target is moving 4 pixels left and 8 pixels up in a given time, but the turret is moving 4 pixels right and 3 pixels up in the same time, the ...

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