Pathfinding weird [solved] + thrown object physics

Started by Scavenger, Sun 14/10/2012 06:38:23

Previous topic - Next topic

Scavenger

I've run into an odd problem when working with my game. In every room, my walking code runs fine, but on this one room, the player character will walk towards a certain spot and not get themselves out of it, no matter how fervently I click
Here is the walkable area map with the position with which the character sticks itself. Why is the character gravitating towards this spot and walking away from it's target? It's all very mysterious, but again, doesn't happen in any room other than this one. I tried my best to break the pathfinding in other rooms but it's just this one that has it. Details could be: I've turned off automatic walking, and done "player.Walk (mouse.x,mouse.y)" in it's stead on on_mouse_click. It's frustrating. Will I have to scrap this room and rebuild it?

Secondly, I've been wracking my brains for a way to implement a certain Legend of Kyrandiaesque inventory system, and so far have had a lot of luck with it. Everything works well, but I'm not satisfied with the way the character drops items. I would like to make it so that it plays something like this:
[imgzoom]https://dl.dropbox.com/u/50882197/throw_object.PNG[/imgzoom]
In which the player clicks on empty space and the character throws it, how far depending on how far away the character is from the target click. Cyan being a walkable area, so that the player doesn't throw items into ravines and stuff. It's wholly unnecessary, but very in-character. I'm just not sure how to make a thrown object arc like that so that it comes to rest roughly around the mouse pointer. I'm not a very good programmer at all!

Calin Leafshade

.Walk takes room coordinates, you're giving it screen coordinates.

This wouldnt matter on a non scrolling room but since your room scrolls you need to take into account the viewport.

use:

player.Walk(mouse.x + GetViewportX(), mouse.y + GetViewportY())

Scavenger

Oh, duh, I knew I was missing something. That was a really stupid mistake of me to make. x3 Thanks!

Khris

Coded a "module": https://www.dropbox.com/s/4nv8xi59wc4qh2w/Bounce0.1.scm

Use it like this:

Code: ags
function room_Load() {
  Bounce.SetDummyChar(cThrowDummy);
  // walkable area bounciness
  Bounce.SetDampening(1, 0.4);
  Bounce.SetDampening(2, 0.2);
  // room's z-axis is squashed to 30%
  Bounce.SetPerspectiveFactor(0.3);
}

void on_mouse_click(MouseButton button) {
  int mx = mouse.x, my = mouse.y;
  // only accept left clicks with item on nothing
  if (button != eMouseLeft) return;
  if (mouse.Mode != eModeUseinv) return;
  if (GetLocationType(mx, my) != eLocationNothing) return;
  player.FaceLocation(mx + GetViewportX(), my + GetViewportY(), eBlock);
  Bounce.Throw(mx, my);
}


Note that it merely moves the dummy character, there's no handling of inventory items whatsoever. The final position of the item is cThrowDummy.x, cThrowDummy.y.

The demo video is uploading right now: http://youtu.be/8--EZZKQGUg

(Just noticed that e.g. the initial height is hardcoded :P. Will probably update later.)

Scavenger

Quote from: Khris on Sun 14/10/2012 17:37:12
Coded a "module": https://www.dropbox.com/s/4nv8xi59wc4qh2w/Bounce0.1.scm

That's perfect! I already use dummy characters for discarded inventory items in the room, so this'll be relatively painless to implement - practically the only thing left to implement is the movement itself. Thankyou so much!

SMF spam blocked by CleanTalk