ok, ive been working on this for days, but im still having problems. i hope Tazz (or someone) can help. hot, i appreciate your reply, but i didnt really understand it =).
ok, so i figured out why nothing was happening. first of all, my Tile_To_World() function was mis-calculating. so thats why nothing was happening.
after i fixed that though, it still took me 2 days to figure out why my guy wasnt moving right. after some torturous debug sessions, i figured out my player was falling off his path. thats why he wont move correctly.
by falling of the path, i mean this:
each frame, i do this:
-find which spot in the path i am in
-move towards the next point in the path (the one after the one im on now)
the problem was, is i was moving too far, or too little, or something was happening, and i was "falling off" the path. basically, i would move too far, and when i go to this point
-find which spot in the path im in
the spot in the path wasnt found, since i wasnt on the path anymore. so my character wouldnt move, since i cant find out where in the path i am now, how do i figure out what the next spot in the path is?
well, i fixed it (sort of). basically, the reason why this was happening (i *think*), was because my player is more then a tile big. so when i would move to a tile, i would move to it, but the top left corner of me would be in the next tile over, which wasnt in the path, so thats how i "fell off" the path.
the "solution" was this:
when i go to calculate the path to take, instead of sending the pathfinder my x,y position, i send it my x + (w/2) , y + (h/2) position. IE, i send the pathfinder my CENTER, not my top left corner. when i go to find what spot in the path im in, i use my CENTER. BUT, when i actually move, i still move based on my x and y position, IE my top left corner position. so i still do xPos += movement.
this worked! im actually moveing through my path. (sort of)
for one, i can only move up,down,left,right. i cannot allow angular movement, or else ill fall off the path. i have no idea how to fix this.im hoping the other kind of interpolation you can show me will fix this.
the other thing is, im still stepping onto walls and stuff. IE, the movement isnt perfect.
anyway, here is what the code looks like so far. this function is called each frame, inside Player::Update().id also like to note, i changed the path_to_walk variable from a std::vector to a std::deque. this is because i needed a pop_front() function. if you look, at the end of the function, inside the for loop where ive found the spot the player is standing on, i loop through the path_to_walk, and pop_front() any variables that were before the path im standing on now. this is because those are path's ive already walked through and are no longer needed, so i dont have old path's still in the container. also, this means path_to_walk[0] *should* always be the path im standing on.
void Player::Do_Pathfinding_And_Movement(){ dx = dy = 0; // HERE IS WHERE I DO PATH_TO_WALK = PATHFINDER.CALCULATE_PATH(), AND CALCULATE THE PATH I SHOULD WALK. (IF THE USER CLICKS ON THE MAP) //first find which step we are in the path //first we calculate the Player's Point Point pp; pp.x = (int)xPos + (PLAYERWIDTH/2); pp.y = (int)yPos + (PLAYERHEIGHT/2); map_data->World_To_Tile(pp.x,pp.y); //if we have a path to walk if(!path_to_walk.empty()) { //for each waypoint in the path to walk //now that we know what tile the player is standing on, lets find which path that is in the pathfinder. for(int i = 0; i < path_to_walk.size(); i++) { //if we found what tile the player is standing on in this path to walk AND this isnt the last node if(pp == path_to_walk.pos && i < (path_to_walk.size() - 1)) { Point dst; //find the next point to move to IN WORLD COORDINATES, and put it in the dst variable dst.x = path_to_walk.pos.x;<br> dst.y = path_to_walk.pos.y;<br> map_data->Tile_To_World(dst.x,dst.y);<br><br> <span class="cpp-comment">// calculate slope</span><br> dy = dst.y - (yPos);<br> dx = dst.x - (xPos);<br><br> <span class="cpp-comment">//find the distance between the target the and shooter</span><br> <span class="cpp-keyword">float</span> diff = sqrt((<span class="cpp-keyword">float</span>)dy*dy + dx*dx);<br><br> <span class="cpp-comment">// normalize and set velocity</span><br> <span class="cpp-keyword">float</span> invlen = <span class="cpp-number">1</span>.0f/diff;<span class="cpp-comment">//((float)dy*dy + dx*dx);</span><br> <br> <span class="cpp-comment">//noramlize the velocity</span><br> dy *= (invlen*<span class="cpp-number">350</span>);<br> dx *= (invlen*<span class="cpp-number">350</span>);<br><br> <span class="cpp-comment">//set my velocity</span><br> xVel = (dx * timer.Time_Passed);<br> yVel = (dy * timer.Time_Passed);<br><br> <span class="cpp-comment">//move at my velocity</span><br> xPos += xVel;<br> yPos += yVel;<br><br> <span class="cpp-comment">//get rid of all the path's that we've already stepped through</span><br> <span class="cpp-keyword">for</span>(<span class="cpp-keyword">int</span> n = <span class="cpp-number">0</span>; n < i; n++)<br> path_to_walk.pop_front();<br><br> <span class="cpp-keyword">return</span>;<br> <br> }<br> }<br> }<br>}<br><br><br><br><br><br></pre></div><!–ENDSCRIPT–><br><br>also, if you want, ive uploaded the game exe for you to check out to see how it looks like. youll be able to see what im talking about when i say the movement isnt "right", IE, how you overlap with walls and stuff. not sure how to just make the damn player move the way i want to =). thanks a lot for all your help!!!<br><br><a href="http://www.donkeypunchproductions.net/help_me.zip"> click here to download</a><br><br>just left click with the mouse to walk around. thanks a lot for anymore help!!