Skip to content

Instantly share code, notes, and snippets.

@majikayogames
majikayogames / apply_clip_shader.gd
Last active April 19, 2025 11:31
A weapon view model clipping prevention shader and function to apply the shader to your models in Godot.
## CC0 license use this function wherever you want no need to credit.
## Call this function on any node to apply the weapon_clip_and_fov_shader.gdshader to all meshes within it.
func apply_clip_and_fov_shader_to_view_model(node3d : Node3D, fov_or_negative_for_unchanged = -1.0):
var all_mesh_instances = node3d.find_children("*", "MeshInstance3D")
if node3d is MeshInstance3D:
all_mesh_instances.push_back(node3d)
for mesh_instance in all_mesh_instances:
var mesh = mesh_instance.mesh
# Important to turn shadow casting off for view model or will cause issues with both
# view model, casting shadows on itself once unclipped, & also will look weird casting on world.
@majikayogames
majikayogames / _push_away_rigid_bodies.txt
Last active May 12, 2025 14:10
Godot 4 CharacterBody3D to RigidBody3D Push Interaction Script
# CC0/public domain/use for whatever you want no need to credit
# Call this function directly before move_and_slide() on your CharacterBody3D script
func _push_away_rigid_bodies():
for i in get_slide_collision_count():
var c := get_slide_collision(i)
if c.get_collider() is RigidBody3D:
var push_dir = -c.get_normal()
# How much velocity the object needs to increase to match player velocity in the push direction
var velocity_diff_in_push_dir = self.velocity.dot(push_dir) - c.get_collider().linear_velocity.dot(push_dir)
# Only count velocity towards push dir, away from character