Godot Version
4.1
Question
extends CharacterBody3D
const SPEED = 4
const JUMP_VELOCITY = 4.8
const TMS = 0.01
var shoot = false
var delay_timer
var current_weapon = null
var rifle_scene = preload("res://akm/akr.tscn")
@onready var weapon_position = get_node("Pos3D")
func _on_button_pressed():
$anim.play("AKM_SHOT")
print("Shoot")
var gravity = 16
func _input(e):
if e is InputEventScreenDrag:
if e.position.x > 540 and $h:
rotation.y -= e.relative.x * TMS
$h.rotation.x = clamp($h.rotation.x - e.relative.y * TMS, -1.4, 1.4)
func _physics_process(delta):
if Input.is_action_just_pressed("akm"):
var objj = load("res://akm/akr.tscn").instance()
weapon_position.add_child(objj)
if not is_on_floor():
velocity.y -= gravity * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
func _on_button_2_pressed():
if is_on_floor():
velocity.y = JUMP_VELOCITY