Snippets Collections
import * as React from 'react';
import {Camera, CameraPermissionStatus} from "react-native-vision-camera";

export default function PermissionsScreen(){
    const [CameraPermissionStatus, setCameraPermissionStatus] = React.u
    return (
        <>
        </>
    )
}
extends CharacterBody3D

@export var speed : float = 6.0
@export var jump_velocity : float = 8.0
@export var look_sensitivity : float = 0.001

@onready var camera : Camera3D = $Camera3D
@onready var head : Node3D = $Head
@onready var pivot : Node3D = $Head/Pivot
@onready var collision_shape = $CollisionShape3D


var gravity : float = ProjectSettings.get_setting("physics/3d/default_gravity")*2
var velocity_y : float = 0
var update : bool = false
var gt_prev : Transform3D
var gt_current : Transform3D
var mesh_gt_prev : Transform3D
var mesh_gt_current : Transform3D

var obstacles : Array
var is_climbing : bool = false

func _ready():
	# Camera set up to prevent jitter.
	camera_setup()
	
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED 
	
func _input(event):
	# Mouse movement.
	if event is InputEventMouseMotion:
		rotate_y(-event.relative.x * look_sensitivity)
		
		head.rotate_x(-event.relative.y * look_sensitivity)
		
		head.rotation.x = clamp(head.rotation.x, -PI/2, PI/2)
		
# In-process func set up for preventing jitter.
func _process(delta):
	if update:
		update_transform()
		
		update = false
		
	var f = clamp(Engine.get_physics_interpolation_fraction(), 0 ,1)
	
	camera.global_transform = gt_prev.interpolate_with(gt_current, f)
	
func _physics_process(delta):
	update = true
	# Basic movement.
	var horizontal_velocity = Input.get_vector("left", "right", "forward", "backward").normalized() * speed
	
	velocity = horizontal_velocity.x * global_transform.basis.x + horizontal_velocity.y * global_transform.basis.z
	
	# Checking if the player is on the floor or climbing.
	if not is_on_floor() and not is_climbing:    
		velocity_y -= gravity * delta
		
	else:
		velocity_y = 0
		
	# Jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity_y = jump_velocity 
		
	# Vaulting with place_to_land detection and animation.
	vaulting(delta)
	
	velocity.y = velocity_y
	move_and_slide()
	
# Camera set up to prevent jitter.
func camera_setup():
	camera.set_as_top_level(true)
	
	camera.global_transform = pivot.global_transform
	
	gt_prev = pivot.global_transform
	
	gt_current = pivot.global_transform
	
# Updating transform to interpolate the camera's movement for smoothness. 
func update_transform():
	gt_prev = gt_current
	
	gt_current = pivot.global_transform
	
# Creating RayCast via code.
func raycast(from: Vector3, to: Vector3):
	var space = get_world_3d().direct_space_state
	
	var query = PhysicsRayQueryParameters3D.create(from, to, 2)
	
	query.collide_with_areas = true
	
	return space.intersect_ray(query)

# Calculating the place_to_land position and initiating the vault animation.
func vaulting(delta):
	if Input.is_action_just_pressed("jump"):
		# Player's RayCast to detect climbable areas.
		var start_hit = raycast(camera.transform.origin, camera.to_global(Vector3(0, 0, -1)))
		
		if start_hit and obstacles.is_empty():
			# RayCast to detect the perfect place to land. (Not that special, I just exaggerate :D)
			var place_to_land = raycast(start_hit.position + self.to_global(Vector3.FORWARD) * collision_shape.shape.radius + 
			(Vector3.UP * collision_shape.shape.height), Vector3.DOWN * (collision_shape.shape.height))
			
			if place_to_land:
				# Playing the animation
				vault_animation(place_to_land)

# Animation for vaulting/climbing.
func vault_animation(place_to_land):
	# Player is climbing. This variable prevents hiccups along the process of climbing.
	is_climbing = true
	
	# First Tween animation will make player move up.
	var vertical_climb = Vector3(global_transform.origin.x, place_to_land.position.y, global_transform.origin.z)
	# If your player controller's pivot is located in the middle use this: 
	# var vertical_climb = Vector3(global_transform.origin.x, (place_to_land.position.y + collision_shape.shape.height / 2), global_transform.origin.z)
	var vertical_tween = get_tree().create_tween().set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN)
	vertical_tween.tween_property(self, "global_transform:origin", vertical_climb, 0.4)
	
	# We wait for the animation to finish.
	await vertical_tween.finished
	
	# Second Tween animation will make the player move forward where the player is facing.
	var forward = global_transform.origin + (-self.basis.z * 1.2)
	var forward_tween = get_tree().create_tween().set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN_OUT)
	forward_tween.tween_property(self, "global_transform:origin", forward, 0.3)
	
	# We wait for the animation to finish.
	await forward_tween.finished
	
	# Player isn't climbing anymore.
	is_climbing = false

# Obstacle detection above the head.
func _on_obstacle_detector_body_entered(body):
	if body != self:
		obstacles.append(body)

func _on_obstacle_detector_body_exited(body):
	if body != self :
		obstacles.remove_at(obstacles.find(body))
extends CharacterBody3D

signal health_changed(health_value)

@onready var camera = $Camera3D
@onready var anim_player = $AnimationPlayer
@onready var muzzle_flash = $Camera3D/gun/MuzzleFlash
@onready var raycast = $Camera3D/RayCast3D

@onready var health = 5

const SPEED = 10.0
const JUMP_VELOCITY = 10.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = 20.0

func _enter_tree():
	set_multiplayer_authority(str(name).to_int())

func _ready():
	if not is_multiplayer_authority(): return
	
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	camera.current = true

func _unhandled_input(event):
	if not is_multiplayer_authority(): return
	
	if event is InputEventMouseMotion:
		rotate_y(-event.relative.x * .005)
		camera.rotate_x(-event.relative.y * .005)
		camera.rotation.x = clamp(camera.rotation.x, -PI/2, PI/2)
	
	if Input.is_action_just_pressed("shoot") \
			and anim_player.current_animation != "shoot":
		play_shoot_effects.rpc()
		if raycast.is_colliding():
			var hit_player = raycast.get_collider()
			hit_player.receive_damage.rpc_id(hit_player.get_multiplayer_authority())

func _physics_process(delta):
	if not is_multiplayer_authority(): return
	
	# 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)

	if anim_player.current_animation == "shoot":
		pass
	elif input_dir != Vector2.ZERO and is_on_floor():
		anim_player.play("move")
	else:
		anim_player.play("idle")

	move_and_slide()

@rpc("call_local")
func play_shoot_effects():
	anim_player.stop()
	anim_player.play("shoot")
	muzzle_flash.restart()
	muzzle_flash.emitting = true

@rpc("any_peer")
func receive_damage():
	health -= 1
	if health <= 0:
		health = 3
		position = Vector3.ZERO
	health_changed.emit(health)

func _on_animation_player_animation_finished(anim_name):
	if anim_name == "shoot":
		anim_player.play("idle")
func upnp_setup():
	var upnp = UPNP.new()
	
	var discover_result = upnp.discover()
	assert(discover_result == UPNP.UPNP_RESULT_SUCCESS, \
		"UPNP Discover Failed! Error %s" % discover_result)

	assert(upnp.get_gateway() and upnp.get_gateway().is_valid_gateway(), \
		"UPNP Invalid Gateway!")

	var map_result = upnp.add_port_mapping(PORT)
	assert(map_result == UPNP.UPNP_RESULT_SUCCESS, \
		"UPNP Port Mapping Failed! Error %s" % map_result)
	
	print("Success! Join Address: %s" % upnp.query_external_address())
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 Aug 23 2024 02:59:19 GMT+0000 (Coordinated Universal Time)

#glsl
star

Sun Jun 02 2024 00:04:40 GMT+0000 (Coordinated Universal Time)

#glsl
star

Thu May 23 2024 23:33:13 GMT+0000 (Coordinated Universal Time)

#glsl
star

Wed May 22 2024 03:14:09 GMT+0000 (Coordinated Universal Time)

#glsl
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