File tree 3 files changed +49
-0
lines changed 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ # player-impulse
2
+
3
+ ## Description
4
+
5
+ Remake ` setVelocity ` for players.
6
+
7
+ ## Usage
8
+
9
+ ``` js
10
+ import { applyImpulse } from " ./index" ;
11
+
12
+ applyImpulse (player, vector);
13
+ ```
14
+
15
+ ## Credits
16
+
17
+ This script is made by [ SI Silicon] ( https://github.com/SIsilicon ) , updated by Remember M9 #8416 and Usernam #2058
Original file line number Diff line number Diff line change
1
+ // Script example for ScriptAPI
2
+ // Author: Usernam#2058 <Jayly Discord>
3
+ // Remember M9#8416 <Bedrock Add-Ons>
4
+ // SI Silicon <https://github.com/SIsilicon>
5
+ // Project: https://github.com/JaylyDev/ScriptAPI
6
+
7
+ import { Player , Vector3 } from "@minecraft/server" ;
8
+
9
+ /**
10
+ * Workaround to apply impulse vector to the current velocity of the player.
11
+ * @param player Only Player class, not Entity.
12
+ * @param vector
13
+ */
14
+ export function applyImpulse ( player : Player , vector : Vector3 ) {
15
+ const { x, y, z } = vector ;
16
+ const horizontal = Math . sqrt ( x * x + z * z ) * 2.0 ;
17
+ const vertical = y < 0.0 ? 0.5 * y : y ;
18
+ player . applyKnockback ( x , z , horizontal , vertical ) ;
19
+ }
Original file line number Diff line number Diff line change
1
+ // Script example for ScriptAPI
2
+ // Author: Usernam#2058 <Jayly Discord>
3
+ // Project: https://github.com/JaylyDev/ScriptAPI
4
+
5
+ import { applyImpulse } from "./index" ;
6
+ import { Vector3 , world } from "@minecraft/server" ;
7
+
8
+ const armorStand = [ ...world . getDimension ( "overworld" ) . getEntities ( { type : 'minecraft:armor_stand' } ) ] [ 0 ] ;
9
+ const player = world . getAllPlayers ( ) [ 0 ] ;
10
+ const vector : Vector3 = { x : 0 , y : 2 , z : 0 } ;
11
+
12
+ armorStand . applyImpulse ( vector ) ;
13
+ applyImpulse ( player , vector ) ;
You can’t perform that action at this time.
0 commit comments