Player follows mouse

Started by steptoe, Mon 05/12/2011 12:06:38

Previous topic - Next topic

steptoe

Hi

I am trying to incorporate  player follows mouse position and fire via left click.
IE character follows mouse (player has own walkable area.)

At the moment it fires by spacebar which could still be used.

Can get the if mouse x / y do something etc its just getting player to follow.

Not quite sure where to find info as can't see in manual.

Could you help please?

It's not over until the fat lady sings..

monkey0506

Okay, so what you're saying is that you want the player to walk to wherever the mouse is at when they click the left mouse button?

...okay...

Code: ags
function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft) ProcessClick(mouse.x, mouse.y, mouse.Mode);
}


That's included in the default game template. And I'm pretty sure it's covered in the tutorial. And you didn't post any code, so if this isn't relevant then you need to tell us what you've actually done already instead of just saying what you want to do.

arj0n

Quote from: monkey_05_06 on Mon 05/12/2011 12:34:40
Okay, so what you're saying is that you want the player to walk to wherever the mouse is at when they click the left mouse button?
Looks like he means that he wants the player to walk non-stop to wherever the mouse is at (and fire by left mouse button click).

steptoe

#3
Actually:

player walk to wherever mouse cursor is.

Fire with left click whenever.

cheers

EDIT: just seen this. Is this on the right track for firing (amend obviously)?

Code: ags

function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft) {
  // Walk-to script
     ProcessClick(mouse.x,mouse.y,eModeWalkTo);
  }
  else if (button == eMouseRight) {
  // Activate script
     ProcessClick(mouse.x,mouse.y,eModeInteract);
  }
}	




It's not over until the fat lady sings..

Snarky

If what you mean is that the character should constantly walk towards the cursor, then no, that's not the code you want. You'll need something in the repeatedly_execute function. But you don't want to recalculate the walk path every cycle, so  you'll need some cleverer logic to only do the WalkTo if the cursor has moved significantly.

monkey0506

I wasn't sure if that's what he wanted.

If you want the player to follow the mouse around the screen I'd suggest doing this:

- Create a dummy character, name it cDummy.
- Create a view for cDummy, populate the loops with sprite 0, it doesn't need a graphic.
- Add the following to your repeatedly_execute function in GlobalScript.asc:

Code: ags
  cDummy.x = mouse.x;
  cDummy.y = mouse.y;


- Activate the following by:

Code: ags
player.FollowCharacter(cDummy, ...); // fill in dist and eagerness appropriately


I didn't test if FollowCharacter works if cDummy isn't actually Walking or Moveing (sic). If it doesn't you could set cDummy's movement speed very high and call cDummy.Walk/Move every loop.

steptoe

Cheers Monkey

I'll give that a whirl

:=
It's not over until the fat lady sings..

Arjunaz78

How about if the room is the scrolling room? is that can conflict the game? I mean is that it will crash the game?
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

monkey0506

For a scrolling room just offset mouse.x and mouse.y by GetViewportX and GetViewportY.

steptoe

Cheers Monkey

Works brilliantly. However, after tweaking it about (distance,eager,speed etc) I find it not really suitable on this occasion as its difficult to do a slow pixel by pixel move as it were.

No doubt it will come in very useful in a situation where it needs be.

Cheers again

:=

steptoe


It's not over until the fat lady sings..

LUniqueDan

Steptoe, are you trying to make a kind of Space shooter game or something ?
If yes, forgot the character and use a cursor instead.

Otherwise, I'm still trying to figure what you're trying to do.
"I've... seen things you people wouldn't believe. Destroyed pigeon nests on the roof of the toolshed. I watched dead mice glitter in the dark, near the rain gutter trap.
All those moments... will be lost... in time, like tears... in... rain."

steptoe

Khris

Well, in a round-about way, yes I suppose it is a shooter game.

The character moves side to side only and he shoots things with the spacebar.

You have to position yourself and line up the targets and fire.

A cursor (hair) would be inappropriate in this case as it would be too perfect, but I understand what you mean.

I suppose it's Arcade in style.

steptoe




It's not over until the fat lady sings..

LUniqueDan

Quote from: steptoe on Fri 09/12/2011 19:12:44
A cursor (hair) would be inappropriate in this case as it would be too perfect, but I understand what you mean.

I suppose it's Arcade in style.

steptoe

I didn't mean an hair, the character himself as a cursor, then lock the mouse edges using
Code: ags
 Mouse.SetBounds(int left, int top, int right, int bottom) 


Then with some code set the proper animation.

The other posibility is just to ask if the mouse.x is in left part of the screen (<160) or right part of the screen  (>160) then move the character straight to x0 or x320 (or whatever your room size) then use ismousedown in order to make him stopmoving() then proceed your shooting animation/test routine.

At least that's the way I'll do it.
"I've... seen things you people wouldn't believe. Destroyed pigeon nests on the roof of the toolshed. I watched dead mice glitter in the dark, near the rain gutter trap.
All those moments... will be lost... in time, like tears... in... rain."

Khris

Just to be clear about this:
To move a character, you don't have to use .Move or .FollowCharacter. You can directly set the coordinates.

I guess the underlying misunderstanding is the same as in the other thread and steptoe doesn't want the player to follow the mouse as in actually walk in its direction, he simply wants the character at the mouse position, instantly. He's just asking the wrong question because he doesn't have all the info.

This is for some arcade shooter game, right?

Try this in repeatedly_execute:

Code: ags
  player.x = mouse.x;
  player.y = mouse.y;


I could be completely wrong though so if I am, just ignore this.

steptoe

Hi

nice code Khris but it does not conform to the game play as the player must only move to and fro across the walkable area.

Like at the rifle range at the fair: you can move side to side but never forward as it were.

Using 
Code: ags

player.x = mouse.x; 
player.y = mouse.y; 


will move the player anywhere the cursor is, similar to when the player has active inventory attached as you well know.

I'm quite happy as it is, not 100% perfik but durable until such time.

cheers all you guys

:=

PS Maybe you can shed some more light on it if you play the game?



It's not over until the fat lady sings..

Snarky

Quote from: steptoe on Sat 10/12/2011 07:41:00
Hi

nice code Khris but it does not conform to the game play as the player must only move to and fro across the walkable area.

Like at the rifle range at the fair: you can move side to side but never forward as it were.

Using 
Code: ags

player.x = mouse.x; 
player.y = mouse.y; 


So just have it:

Code: ags

player.x = mouse.x; 


That way the player.y won't change, and the character will just slide along the screen from side to side.

SMF spam blocked by CleanTalk