Hot answers tagged movement
8
The typical way of handling this is to create a camera object. The simplest form of a camera is just a position. This simple camera defines the "center" of the current view. So you don't modify all the positions of your tiles/entities, you just subtract the camera coordinates from the positions when drawing. In this situation, the camera does not "move".
...
8
Using a while loop inside your game loop is a basic no-no. Think about how the code is being executed and you'll realize why it just teleported or was frozen and then teleported. (hint: how much of that code do you think is run before the next time your graphics are updated?)
You want to have a target position, then on each iteration of your game loop check ...
5
You don't need to use a grid, you can easily extract node information from the roads (or keep it when placing roads). Path finding only cares about connectivity. Once you get to one node, which nodes can you go to next?
Red dots are nodes in your path finding algorithm. The orange lines define their conectivity.
The Green agent wants to go from its ...
3
Here are 3 standard (pre-calculus) kinematics formulae covering the case of constant acceleration, each with one of the unknowns (t, v, or _d) eliminated:
v^2 = u^2 + 2 a d
v = u + a t
d = u t + a (t^2) / 2
where:
u and v are the unitial and vinal (sic) velocities respectively;
t is the time;
d is the distance travelled in time t; and
a is the constant ...
2
A* is for finding the shortest path from vert a to vert b. Its not a good fit for finding all verts x distance from vert a.
A Depth First Search (DFS) should be suitable for your problem and very cheep on both memory and clock cycles. There is another basic search algorithm called the Breadth First Search (BFS) that would run at similar speeds but uses ...
2
The way to deal with this is to set a timer once the person taps the phone. The most user friendly scenario that you'd implement would look something like this:
When you detect a tap, set a timer (t = timeToRepeat)
On each frame, decrease the timer by dt
If the timer reaches zero, move the sprite a tile and reset the timer
If the user releases their finger ...
2
No this is the wrong way to go about this.
How are you going to do trap detection? What about when the player reaches the edges of the walls? Will your viewing system work for dungeons or will you have to re-write a significant portion of the code?
The world is geometry. The player is geometry. The world doesn't move. The player does. Set the ...
2
You need a variable that stores the position that was clicked ( the target of the object. ) This position could be set when you check the rest of your input like this
MouseState mouseState = Mouse.GetState();
if (lastMouseState.LeftButton == ButtonState.Released && currentMouseState.LeftButton == ButtonState.Pressed)
{
// This will give the ...
2
There are two problems. One, you are setting the velocity directly yet applying it as a force by taking into account the ridged body mass. Two, your "slowing down" is exactly the same as you are speeding up, you are not inverting the speed adjustment.
Though I am unsure why (if the object has a ridged body) you are performing this by hand instead of with ...
1
The way I would do it would be to have my character object have it's own render method, and a member variable to hold direction data. You could make an enum to define the different possible states if you wanted to.
Then within the render method, check what state the direction is in (possibly using a switch/case) and render the corresponding sprite.
Wherever ...
1
To sum up the comments:
Use the following strategy for the arrival behavior. This paper has more information.
target_offset = target - position
distance = length (target_offset)
ramped_speed = max_speed * (distance / slowing_distance)
clipped_speed = minimum (ramped_speed, max_speed)
desired_velocity = (clipped_speed / distance) * target_offset
steering = ...
1
Blame me for never having played any of these games, so I can just assume you want your character to turn around while walking rather than turning instantly (e.g. like in The Legend of Zelda games or most JRPGs).
If so, I'd simplify the whole thing using "steering":
Store the current direction the player is facing as an integer. You can either use 4 or 8 ...
1
I found the problem. First I want to say, Jimmy's answer was useful advice, and I would recommend following it (having everything in radians).
That being said, the problem was incorrect use of atan. Atan has quadrant-case issues, which I did not account for. This can be fixed by using atan2, which was made with that purpose in mind, or manually doing it. ...
Only top voted, non community-wiki answers of a minimum length are eligible