Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local UserInputService = game:GetService("UserInputService")
- local Matter = require(ReplicatedStorage.Shared.Libs.Matter)
- local Components = require(ReplicatedStorage.Shared.Components)
- local PLAYER_SPEED = 500
- local DASH_FORCE = 500
- local function boolToInt(bool)
- return if bool then 1 else 0
- end
- local function PlayersMove(world)
- for id, velocity in world:query(Components.Velocity, Components.LocalPlayer) do
- local moveDirection = Vector2.new(
- boolToInt(UserInputService:IsKeyDown(Enum.KeyCode.D)) - boolToInt(UserInputService:IsKeyDown(Enum.KeyCode.A)),
- boolToInt(UserInputService:IsKeyDown(Enum.KeyCode.S)) - boolToInt(UserInputService:IsKeyDown(Enum.KeyCode.W))
- )
- local unit = if moveDirection ~= Vector2.new(0, 0)
- then moveDirection.Unit
- else moveDirection
- world:insert(id, velocity:patch({
- Velocity = velocity.Velocity + unit * PLAYER_SPEED * Matter.useDeltaTime()
- }))
- end
- for _, input, isTyping in Matter.useEvent(UserInputService, "InputBegan") do
- if isTyping or input.KeyCode ~= Enum.KeyCode.E then
- continue
- end
- for id, transform, velocity in world:query(Components.Transform, Components.Velocity, Components.LocalPlayer) do
- local angle = math.rad(transform.Rotation)
- local value = Vector2.new(math.cos(angle), math.sin(angle)) * DASH_FORCE
- world:insert(id, velocity:patch({
- Velocity = value,
- }))
- end
- end
- end
- return PlayersMove
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement