ID:2253666
 
(See the best response by Kaiochao.)
I would like to know if it is possible to make the player for example turn around on himself when he turns his mouse around him?

To be more specific:

I would like the player to change the direction they're facing based on the mouse position and then be able to shoot a projectile in this direction when they click the left-click?
So, you want to make the player face the mouse, and fire projectiles toward the mouse?
(I've made a few BYOND games with this, and I think BYOND needs more of them.)

It helps to have working knowledge of vectors.

1. You need to track the position of the mouse.
There are libraries for this.

2. Get the direction from the player to the mouse.
Subtract the mouse's world-position by the player's world-position, and then normalize the result.
This can be used to get a rotation matrix for the projectile, as well as the velocity of the projectile.
It can also be used to determine the direction for the player to face.

If you have questions, ask away.
Yes I want the mouvements to still be WASD but the player face the mouse but I don't need to control the range of the projectile with the mouse I just need it to be the direction of the projectile.

I don't know if that's what you tought I want.

And do you know a good up to date library to track the mouse or I can take anyone?
Something as simple as this isn't that simple within BYOND, mouse control is very poor at the moment killing the amount of players you could have on a single server.
In response to Louis53
Are you using pixel movement?
No i'm not using pixel movement.
Can you guys help me on this or is it a no-hope case?
Best response
For tile movement, you can probably just use MouseEntered and MouseDrag to track the object under the mouse, and get_dir() to get the direction from the player to the object under the mouse. MouseDown can be used to fire a shot.
In response to Kaiochao
Can it really be as simple as using already built in proc? :P

But I never used these proc so I don't really know how to use them D:
In response to Louis53
Louis53 wrote:
Can it really be as simple as using already built in proc? :P

But I never used these proc so I don't really know how to use them D:

What Kaiochao said and press F1 in dream maker.
In response to Louis53
// To override a built-in proc:

// 1. Navigate to the path that the proc was originally defined under.
// For client/MouseEntered(), it's under client.
client

// 2. Type the exact name of the proc,
// followed by the arguments that it is defined to take.
MouseEntered(object, location, control, params)

// 3. Usually, you want the previous definition to run.
// That's what this, the ".. proc", does.
..()

// 4. Add your own code.
// This changes the direction of the mob (of this client)
// to face the object under the mouse pointer.
mob.dir = get_dir(mob, object)

// Similarly, override MouseDrag if you want it to happen while a mouse button is pressed.
// (MouseEntered() is only called when no mouse buttons are pressed.)
MouseDrag(src_object, over_object, src_location, over_location, src_control, over_control, params)
..()

// In this case, over_object is the object under the mouse pointer.
// (src_object is the object that was mouse-down'd to start the drag)
mob.dir = get_dir(mob, over_object)

// And for shooting when the left mouse button is pressed:
MouseDown(object, location, control, params)
..()
// This is how the params argument can be used to determine
// whether the pressed mouse button was the "left" mouse button.
var list/p = params2list(params)
if(p["left"])
mob.Shoot()
In response to Maximus_Alex2003
Maximus_Alex2003 wrote:
Louis53 wrote:
Can it really be as simple as using already built in proc? :P

But I never used these proc so I don't really know how to use them D:

What Kaiochao said and press F1 in dream maker.

Yes that's true I'll go check it

Kaiochao wrote:
> // To override a built-in proc:
>
> // 1. Navigate to the path that the proc was originally defined under.
> // For client/MouseEntered(), it's under client.
> client
>
> // 2. Type the exact name of the proc,
> // followed by the arguments that it is defined to take.
> MouseEntered(object, location, control, params)
>
> // 3. Usually, you want the previous definition to run.
> // That's what this, the ".. proc", does.
> ..()
>
> // 4. Add your own code.
> // This changes the direction of the mob (of this client)
> // to face the object under the mouse pointer.
> mob.dir = get_dir(mob, object)
>
> // Similarly, override MouseDrag if you want it to happen while a mouse button is pressed.
> // (MouseEntered() is only called when no mouse buttons are pressed.)
> MouseDrag(src_object, over_object, src_location, over_location, src_control, over_control, params)
> ..()
>
> // In this case, over_object is the object under the mouse pointer.
> // (src_object is the object that was mouse-down'd to start the drag)
> mob.dir = get_dir(mob, over_object)
>
> // And for shooting when the left mouse button is pressed:
> MouseDown(object, location, control, params)
> ..()
> // This is how the params argument can be used to determine
> // whether the pressed mouse button was the "left" mouse button.
> var list/p = params2list(params)
> if(p["left"])
> mob.Shoot()
>


Thanks a lot I'll try to make it work on my game!
In response to Kaiochao
Kaiochao wrote:
>   // And for shooting when the left mouse button is pressed:
> MouseDown(object, location, control, params)
> ..()
> // This is how the params argument can be used to determine
> // whether the pressed mouse button was the "left" mouse button.
> var list/p = params2list(params)
> if(p["left"])
> mob.Shoot()
>


Maybe i'm just stupid or I failed to write my code somewhere but it seems I struggle to call my Shoot() proc with mob.Shoot() (turns out I had exactly this proc) it returns mob.Shoot(): undefined proc so I try putting the "Shoot()" code as mob/proc(but it seems I can't call my mob/player/client var in there) and as mob/player/client/verb and it still don't work D:

Sorry if I ask lot of questions i'm still a beginner coder :D
A clients "mob" variable is defined as a /mob, so if your Shoot() is only defined under a specific type of mob, /mob/player/client, then you have to typecast:
if(istype(mob, /mob/player/client))
var mob/player/client/shooter = mob
shooter.Shoot()
Oh thanks a lot is it the same for vars I need to specify because I have vars define under mob/player/client but if I want to call them in a proc do I need to specify that it is a mob/player/client proc?

Sorry if im asking probably basic questions like this

Edit: The mouse proc worked well but is there a way to make the char face for exemple NORTH-EAST and to change the orientation he is facing while moving with WASD?

PS: Sorry if i'm asking a lot
Test #1:

Didn't succeed to make the char follow the right orientation while moving.

I'm trying to find a way to make it work
In response to Louis53
I'm guessing the problem is that movement changes the player's direction, but you want the player to only face towards the mouse?

The built-in proc that causes direction changes is /atom/movable/Move().

/atom/movable is inherited by /mob, so mobs can move.

You can override the built-in Move() proc of the player to not change direction like so:
mob/player/client
Move(atom/new_loc, new_dir)
// The new dir should just be the old dir.
new_dir = dir
return ..()
In response to Kaiochao
Oh yea it worked now thank a lot when I move the player face the mouse but it is really not fluid because in between for example EAST and SOUTH the direction doesnt change the animation so the result is really messy as you can see here:
The projectile are also really messy



I don't know how to make North-East direction for example work D:
So basically, if you aren't EXACTLY to the right, you won't get "EAST" returned by the basic get_dir(). Get_dir() returned the direction of the next step you'd have to take to get from A to B, not necessarily the 'average' direction between the two. And if you are not lined up with the same x-coordinate, it will always attempt to move diagonally, essentially knocking out two movements in one. You'll have to make an algorithm that can approximate the direction for yourself.
Page: 1 2