• Home
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
Godot Community

Godot Community

How to fix that camera doesnt work

Scheduled Pinned Locked Moved GDScript
1 Posts 1 Posters 25 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Danyal Assiundefined Offline
    Danyal Assiundefined Offline
    Danyal Assi
    wrote on last edited by
    #1

    Hello, camera isnt working at all and i dont know why
    here's the whole code:

    extends CharacterBody3D
    
    @onready var armature = $Armature
    @onready var spring_arm_pivot = $SrpingArmPivot
    @onready var spring_arm = $SrpingArmPivot/SpringArm3D
    @onready var anim_tree = $AnimationTree
    
    const SPEED = 5.0
    const LERP_VAL = .15
    
    var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
    
    func _ready():
    	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    
    func _physics_process(delta):
    	# Add the gravity.
    	if not is_on_floor():
    		velocity.y -= gravity * delta
    
    func _unhandled_input(event):
    	if Input.is_action_just_pressed("quit"):
    		get_tree().quit()
    	
    	if event is InputEventMouseMotion:
    		spring_arm_pivot.rotate_y(-event.relative.x * .005)
    		spring_arm.rotate_x(-event.relative.y * .005)
    		spring_arm.rotation.x = clamp(spring_arm.rotation.x, -PI/4, PI/4)
    
    	# 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", "forward", "backward")
    	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
    	direction = direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
    	if direction:
    		velocity.x = lerp(velocity.x, direction.x * SPEED, LERP_VAL)
    		velocity.z = lerp(velocity.z, direction.z * SPEED, LERP_VAL)
    		armature.rotation.y = lerp_angle(armature.rotation.y, atan2(-velocity.x,-velocity.z), LERP_VAL)
    	else:
    		velocity.x = lerp(velocity.x, 0.0, LERP_VAL)
    		velocity.z = lerp(velocity.z, 0.0, LERP_VAL)
    
    
    	anim_tree.set("parameters/BlendSpace1D/blend_position", velocity.length() / SPEED)
    
    	move_and_slide()
    
    1 Reply Last reply
    1

© 2023 Godot Community
Privacy - Terms - Contact

  • Login

  • Don't have an account? Register

Powered by Godot Community
  • First post
    Last post
0
  • Home
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Login

  • Don't have an account? Register