Jump to content

  • Log In with Google      Sign In   
  • Create Account

0026sd

Member Since 20 Sep 2012
Offline Last Active Jul 28 2016 08:01 AM

Posts I've Made

In Topic: Pathfinding - How To Move Player Along Path

22 July 2016 - 02:42 PM

************

** SOLVED  **

************

 

OK, I've solved this issue by doing the following (CodePen has been updated).

  1. Commented out the line where I was adjusting the player's position to snap to the grid.
  2. Reverted back to using the player x and y (not the centers) and the path coordinate x and y (not centers)

That's it. Now it can travel at any speed and go all directions.

 

Apologies if I've wasted anyone's time. I've literally been staring at this for hours.


In Topic: Pathfinding - How To Move Player Along Path

22 July 2016 - 02:05 PM

Just grasping at straws here since I didn't dig too deep into your code, but the physics update function looks... wonky.

maxSpeed should be compared to the magnitude of the velocity vector, not the components of the vector, for one thing. But something smells off in that code overall. Try simplifying it by removing acceleration and drag, and just applying a velocity vector to the current position vector every tick. That might reveal something.

 

Ok, I've adjusted my CodePen, however, it remains the same.

You do bring up a good point, though. That ApplyPhysics() function was converted from C# from a sample game that came with XNA (now MonoGame) and I wasn't sure how to multiply 2 vectors in javascript.

 

i.e.: this.pos * this.velocity;

as opposed to what I had; this.pos.x * this.velocity.x //etc...


In Topic: Help With 2D Collision (Sticky Wall Sliding)

10 June 2016 - 08:26 AM

When you loop through your list of tiles, you use localBoundsRect against each tile. You move the location of the player but don't update the value of localBoundsRect. If your player intersects with two blocks then the overlap is corrected for each block moving the player twice as far as needed. I would recommend setting the position of the player relative to localBoundsRect using the depth as an offset. You can repeat that multiple times without any negative side effects.

 

Updated JS FIDDLEhttps://jsfiddle.net/L7an0c1g/3/

 

OK, so I've applied the changes you suggested and it works except for one thing. The ELSE portion of my IF statement, checking intersection depths beginning on line 203, was intending to correct the player's position if the depth on both axes were the same (hit a corner). When I set my position x,y to the localBoundsRect + depth, it stops the player when sliding on a wall. I think it's because the player is hitting the corner of the tile it's moving into and correcting both the x and the y, stopping him.

 

Right now, after commenting out the else block, if you press W + A simultaneously, the player should pass through the corner tile and stop when it is fully in that tile. Uncommenting the else block will fix this but cause the issue mentioned above (sticky wall sliding).

 

I have read that this is a common issue with corners and maybe it just comes down to level design to minimize that from happening, but if you have any thoughts on how to correct this it would be greatly appreciated.

 

Thanks!


In Topic: Help With 2D Collision (Sticky Wall Sliding)

09 June 2016 - 08:53 PM

When you loop through your list of tiles, you use localBoundsRect against each tile. You move the location of the player but don't update the value of localBoundsRect. If your player intersects with two blocks then the overlap is corrected for each block moving the player twice as far as needed. I would recommend setting the position of the player relative to localBoundsRect using the depth as an offset. You can repeat that multiple times without any negative side effects.

 

Thank you for your reply!! Sounds like it's exactly what my problem is - I'll give it a try tomorrow and let you know how it went!


In Topic: SFML Frame Per Second feedback

31 October 2012 - 11:12 AM

What is the cpu % if you don't make the FPS call in your loop?


I believe it's around 3% or so..

PARTNERS