Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 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.     if is_moving:
  44.         var _rotation = Vector3(0,get_node("CameraHolder").rotation.y,0)
  45.         var new_basis = Basis(_rotation)
  46.         transform.basis = transform.basis.slerp(new_basis, 0.1)
  47.        
  48.         # Your Code
  49.        
  50.         var angle = atan2(velocity.x, velocity.y)
  51.        
  52.         var char_rot = character.get_rotation()
  53.        
  54.         char_rot.y = angle
  55.        
  56.         character.set_rotation(char_rot)
  57.        
  58.         # Your Code
  59.        
  60.     velocity = move_and_slide(velocity, Vector3(0, 1, 0))
  61.    
  62.        
  63. func jump():
  64.     if Input.is_action_just_pressed("jump") and is_on_floor():
  65.         velocity.y = 16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement