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?
1
2
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?
|
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 What Kaiochao said and press F1 in dream maker. |
In response to Louis53
|
|
// To override a built-in proc: |
In response to Maximus_Alex2003
|
|
Maximus_Alex2003 wrote:
Louis53 wrote: Yes that's true I'll go check it Kaiochao wrote: > // To override a built-in proc: 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: 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)) |
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 |
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 |
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.
|
1
2
(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.