Snippets Collections
extends CharacterBody3D

# Enum for weapon states


enum WeaponState {
	UNEQUIPPED,
	EQUIPPED
}
var current_state = WeaponState.UNEQUIPPED
@onready var mesh_root = $MeshRoot

@export var S_H = 0.1
@export var S_v = 0.1
@onready var animation_player = $MeshRoot/AuxScene/AnimationPlayer
@onready var C_M = $Node3D
@onready var weapon = $MeshRoot/AuxScene/ALS_AnimMan_CharacterBP/Skeleton3D/BoneAttachment3D2/Sketchfab_Scene


var SPEED = 2
const JUMP_VELOCITY = 4.5
var running = false
var aiming = false

var running_speed = 5
var walking_speed = 2

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

func _ready():
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	weapon.hide()  # Hide the weapon initially

func _input(event):
	if event is InputEventMouseMotion:
		rotate_y(deg_to_rad(-event.relative.x * S_H))
		C_M.rotate_x(deg_to_rad(-event.relative.y * S_v))

	if event.is_action_pressed("equip_weapon"): 
		if current_state == WeaponState.UNEQUIPPED:
			equip_weapon()
		elif current_state == WeaponState.EQUIPPED:
			unequip_weapon()

	if event.is_action_pressed("aim_weapon") and current_state == WeaponState.EQUIPPED:
		start_aiming()
	elif event.is_action_released("aim_weapon") and current_state == WeaponState.EQUIPPED:
		stop_aiming()

	if event.is_action_pressed("fire_weapon") and current_state == WeaponState.EQUIPPED and aiming:
		fire_weapon()

func _physics_process(delta):
	if Input.is_action_pressed("run"):
		SPEED = running_speed
		running = true
	else:
		SPEED = walking_speed
		running = false

	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	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:
		if running:
			if current_state == WeaponState.EQUIPPED:
				if animation_player.current_animation != "gun_running":
					animation_player.play("RifleRun(2)0")
			else:
				if animation_player.current_animation != "running":
					animation_player.play("Running(2)0")
		else:
			if current_state == WeaponState.EQUIPPED:
				if animation_player.current_animation != "gun_walking":
					animation_player.play("RifleWalk(1)0")
			else:
				if animation_player.current_animation != "walking":
					animation_player.play("WalkWithBriefcase0")
					
					
		mesh_root.look_at(position + direction)
						
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		if current_state == WeaponState.EQUIPPED:
			if aiming:
				if animation_player.current_animation != "gun_aiming":
					animation_player.play("aim")
			else:
				if animation_player.current_animation != "gun_idle":
					animation_player.play("RifleIdle(1)0")
		else:
			if animation_player.current_animation != "idle":
				animation_player.play("Idle(3)0")
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()

# Function to equip the weapon
func equip_weapon():
	current_state = WeaponState.EQUIPPED
	animation_player.play("RiflePullOut(1)0")  # Play equip animation
	weapon.show()  # Make weapon visible

# Function to unequip the weapon
func unequip_weapon():
	current_state = WeaponState.UNEQUIPPED
	animation_player.play("RiflePutAway(1)0")  # Play unequip animation
	weapon.hide()  # Hide weapon after unequip

# Function to start aiming
func start_aiming():
	aiming = true
	animation_player.play("aim")  # Play aiming animation

# Function to stop aiming
func stop_aiming():
	aiming = false
	animation_player.play("gun_idle")  # Play idle animation with gun

# Function to handle firing the weapon
func fire_weapon():
	animation_player.play("FiringRifle(2)0")  # Play fire animation

# Optionally, handle animation finished signal to perform actions after animation ends
func _on_AnimationPlayer_animation_finished(anim_name):
	if anim_name == "unequip":
		weapon.hide()
	elif anim_name == "equip":
		weapon.show()
	elif anim_name == "gun_fire":
		if aiming:
			animation_player.play("aim")  # Return to aiming animation after firing
		else:
			animation_player.play("RifleIdle(1)0")
extends CharacterBody3D

# Enum for weapon states
enum WeaponState {
	UNEQUIPPED,
	EQUIPPED
}
var current_state = WeaponState.UNEQUIPPED


@export var S_H = 0.1
@export var S_v = 0.1
@onready var animation_player = $MeshRoot/AuxScene/AnimationPlayer
@onready var C_M = $Node3D

var SPEED = 2
const JUMP_VELOCITY = 4.5
var running = false

var running_speed = 5
var walking_speed = 2



# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

func _ready():
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	
	
func _input(event):
	if event is InputEventMouseMotion:
		rotate_y(deg_to_rad(-event.relative.x*S_H))
		C_M.rotate_x(deg_to_rad(-event.relative.y*S_v))

func _physics_process(delta):
	
	if Input.is_action_pressed("run"):
		SPEED = running_speed
		running = true
	else:
		SPEED = walking_speed
		running = false
		
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	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:
		if running:
			if animation_player.current_animation != "running":
				animation_player.play("Running(2)0")
		else:
			if animation_player.current_animation != "WalkWithBriefcase0":
				animation_player.play("WalkWithBriefcase0")
			

		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		if animation_player.current_animation != "idle":
			animation_player.play("Idle(3)0")
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()
extends Node3D


@onready var ap = $AuxScene/AnimationPlayer
@onready var raycast = $RayCast3D
@onready var eyes = $eyes
@onready var nav = $NavigationAgent3D

const speed = 5


enum {
	IDLE,
	ALERT,
	STUNND,
	CHASING
}

var target
const  T_S = 2
var state = IDLE

func _ready():
	pass # Replace with function body.

func _process(delta):
		
	match state:
		IDLE:
			ap.play("RifleIdle0")
		ALERT:
			ap.play("FiringRifle0")

			eyes.look_at(target.global_transform.origin, Vector3.UP)
			rotate_y(deg_to_rad(eyes.rotation.y * T_S))
			var direction = (target.global_transform.origin - global_transform.origin).normalized()
		CHASING:
			ap.play("RifleRun0")
			
func _on_area_3d_body_entered(body):
	if body.is_in_group("player"):
		state = ALERT
		target = body

func _on_area_3d_body_exited(body):
	if body.is_in_group("player"):
		state = CHASING



	if Input.is_action_just_pressed("spell"):
		if animation_player.current_animation != "Armature|Shoot":
			animation_player.play("Armature|Shoot")
extends CharacterBody2D


@export var speed :float = 100.0
@export var jump_velocity = -200.0
@onready var aps = $AnimatedSprite2D
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var animation_locked : bool = false
var direction : Vector2 = Vector2.ZERO

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = jump_velocity

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	direction = Input.get_vector("left", "right","up", "down" )
	if direction:
		velocity.x = direction.x * speed
	else:
		velocity.x = move_toward(velocity.x, 0, speed)

	move_and_slide()
	update_animation()
	update_facing_direction()

func update_animation():
	if not animation_locked:
		if direction.x != 0:
			aps.play("run")
		else:
			aps.play("idle")

func update_facing_direction():
	if direction.x > 0:
		aps.flip_h = false
	elif direction.x < 0:
		aps.flip_h = true

func jump():
	velocity.y = jump_velocity
	aps.play("jump")
	animation_locked = true
extends CharacterBody3D

var mouse_sense = 0.1 
const SPEED = 5.0
const JUMP_VELOCITY = 4.5

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")


@onready var head = $head
@onready var camera = $head/Camera3D

func _ready():
	#hides the cursor
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)


func _input(event):
	#get mouse input for camera rotation
	if event is InputEventMouseMotion:
		rotate_y(deg_to_rad(-event.relative.x * mouse_sense))
		head.rotate_x(deg_to_rad(-event.relative.y * mouse_sense))
		head.rotation.x = clamp(head.rotation.x, deg_to_rad(-89), deg_to_rad(89))


func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir = Input.get_vector("left", "right", "up", "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()
shader_type spatial;
render_mode cull_front, unshaded;

uniform vec4 outline_color : source_color;
uniform float outline_width = 1.0;

void vertex() {
	vec4 clip_position = PROJECTION_MATRIX * (MODELVIEW_MATRIX * vec4(VERTEX, 1.0));
	vec3 clip_normal = mat3(PROJECTION_MATRIX) * (mat3(MODELVIEW_MATRIX) * NORMAL);
	
	vec2 offset = normalize(clip_normal.xy) / VIEWPORT_SIZE * clip_position.w * outline_width * 2.0;
	
	clip_position.xy += offset;
	
	POSITION = clip_position;
}

void fragment() {
	ALBEDO = outline_color.rgb;
	if (outline_color.a < 1.0) {
		ALPHA = outline_color.a;
	}
}
star

Fri May 17 2024 04:41:00 GMT+0000 (Coordinated Universal Time)

#glsl
star

Fri May 17 2024 02:06:27 GMT+0000 (Coordinated Universal Time)

#glsl
star

Fri May 03 2024 23:05:41 GMT+0000 (Coordinated Universal Time)

#glsl
star

Thu May 02 2024 02:58:07 GMT+0000 (Coordinated Universal Time)

#glsl
star

Wed Apr 03 2024 21:42:26 GMT+0000 (Coordinated Universal Time)

#glsl
star

Sat Mar 16 2024 03:29:40 GMT+0000 (Coordinated Universal Time)

#glsl
star

Sat Mar 16 2024 03:23:35 GMT+0000 (Coordinated Universal Time) https://godotshaders.com/shader/pixel-perfect-outline-shader/

#glsl

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension