# Solved Using Yaw to propulse a player forward

Discussion in 'Plugin Development' started by Betagear, Jul 18, 2015.

Not open for further replies.
1. Offline

### Betagear

Hi.
I am currently trying to improve my plugin, And i used a command line that makes the player do a dash in the direction that he is looking. But, there is an issue : If the player looks at the ground or in the air, the dash doesn't do much. Here is the code :
Code:
```Vector dir = player.getLocation().getDirection().multiply(3);
Vector vec = new Vector(dir.getX(), 0, dir.getZ());
player.setVelocity(vec);```
I think using getYaw would be better, but I don't know how to use it.
Any help ?

#1
2. Offline

### _Filip

The yaw is an angle

I don't really know for sure but something like new Vector(90 / yaw, y value, 90 / (yaw - 90)) might work

Last edited by a moderator: Jul 18, 2015
#2
3. Offline

### Forge_User_40559162

Just set the pitch to 0 .problem solved

4. Offline

### _Filip

How did I not think or this...

#4
5. Offline

### Betagear

This isn't a solution, since I don't want to reset the player's pitch, and so I really think that the yaw for me is the solution.
I don't know how to do this, but if there is a function to do that :

0° Yaw : Velocity X = 1, Velocity Z = 0
90° Yaw : Velocity X = 0, Velocity Z = 1
180° -180° Yaw : Velocity X = -1, Velocity Z = 0
-90° Yaw : Velocity X = 0, Velocity Z = -1​
Maybe by adding 180° to that this would be more simple.
Something to vary that.
But thanks all for your help.

EDIT : This isn't a solution, because Yaw is glitched. The best way would be to normalize the Y axis of getDirection to do that the players are always propelled at the same speed. (Excuse me for my english, I'm french)

Last edited: Jul 19, 2015
#5
6. Offline

### Forge_User_40559162

It is a solution. You don't set the players pitch to 0, you need to set the locations pitch to 0 and then use .getDirection() etc.

7. Offline

### Betagear

I tried
Code:
```            player.getLocation().setPitch(0);
Vector dir = player.getLocation().getDirection().multiply(force);
vec = new Vector(dir.getX(), Yvelocity, dir.getZ());```
but it doesn't works. Still no dash when the player looks down or up.

#7
8. Offline

### Forge_User_40559162

.getLocation() returns a duplicate.
Assign the location to a variable, change the pitch, use the variable in your vector calculation

9. Offline

### Betagear

Used that :
Code:
```            Location Dash = player.getLocation();
Dash.setPitch(0);
Vector dir = Dash.getDirection().multiply(force);
vec = new Vector(dir.getX(), Yvelocity, dir.getZ());```
and it worked ! Thanks a lot ! I wouldn't have find it myself.

#9
10. Offline

### Forge_User_40559162

`vec = Dash.getDirection().multiply(force).setY(Yvelocity);`