Advertisement
Guest User

Hello, Jayanam

a guest
Feb 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. extends KinematicBody
  2.  
  3. var speed = 20
  4. var gravity = -9.8
  5. var direction = Vector3(0, 0, 0)
  6. var velocity = Vector3(0, 0, 0)
  7. var is_moving
  8. var character
  9.  
  10. func _ready():
  11.     character = get_node(".")
  12.  
  13. func _physics_process(delta):
  14.     jump()
  15.     movement(delta)
  16.    
  17. func movement(delta):
  18.     direction = Vector3(0, 0, 0)
  19.     is_moving = false
  20.     if Input.is_action_pressed("W"):
  21.         direction += transform.basis.z
  22.         is_moving = true
  23.     if Input.is_action_pressed("S"):
  24.         direction -= transform.basis.z
  25.         is_moving = true
  26.     if Input.is_action_pressed("A"):
  27.         direction += transform.basis.x
  28.         is_moving = true
  29.     if Input.is_action_pressed("D"):
  30.         direction -= transform.basis.x
  31.         is_moving = true
  32.        
  33.        
  34.     direction = direction.normalized()
  35.    
  36.     direction = direction * speed
  37.    
  38.     velocity.x = direction.x
  39.     velocity.z = direction.z   
  40.    
  41.     velocity.y += gravity * delta
  42.    
  43.     # Your Code
  44.     if is_moving:
  45.        
  46.         var angle = atan2(velocity.x, velocity.y)
  47.        
  48.         var char_rot = character.get_rotation()
  49.        
  50.         char_rot.y = angle
  51.        
  52.         character.set_rotation(char_rot)
  53.        
  54.         # Your Code
  55.        
  56.     velocity = move_and_slide(velocity, Vector3(0, 1, 0))
  57.    
  58.        
  59. func jump():
  60.     if Input.is_action_just_pressed("jump") and is_on_floor():
  61.         velocity.y = 16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement