Advertisement
metalx1000

Godot Multiplayer Controls

May 30th, 2022
2,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ######################################################################
  2. #Copyright (C) 2022  Kris Occhipinti
  3. #https://filmsbykris.com
  4.  
  5. #This program is free software: you can redistribute it and/or modify
  6. #it under the terms of the GNU General Public License as published by
  7. #the Free Software Foundation, either version 3 of the License, or
  8. #(at your option) any later version.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18.  
  19. extends Sprite
  20.  
  21. var direction = Vector2()
  22. export var speed = 500
  23. export var player_id = 0
  24.  
  25. func _process(delta):
  26.     move(delta)
  27.  
  28. func _input(event):
  29.     if event.device != player_id:
  30.         return
  31.        
  32.     var x = 0
  33.     var y = 0
  34.    
  35.     if Input.is_action_pressed("player_right"):
  36.         x += 1
  37.     elif Input.is_action_pressed("player_left"):
  38.         x -= 1
  39.        
  40.     if Input.is_action_pressed("player_up"):
  41.         y -= 1
  42.     elif Input.is_action_pressed("player_down"):
  43.         y += 1
  44.        
  45.     direction= Vector2(x,y)
  46.  
  47. func move(delta):
  48.     position += direction * speed * delta
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement