2d Sprite in a 3d world

Godot Version

4.2.2 stable

This is my first time working without a tutorial so please bare with me.

Im trying to get animated3d sprite to move around a 3d world. when the sprite moves i want the animation frames i set up to show so if i press right the right walk animation will play.

so far i havent been able to get the character to move or show the animations.
besides the assignment error whats wrong with my code. i dont understand what im missing.

here is my code and pictures. thank you in advance.

Code:

extends CharacterBody3D

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”)

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

# Handle jump.
if Input.is_action_just_pressed("jump") 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", "forward", "back")
var direction = Vector2 = (get_global_sprite_position() - global_position).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 Input.is_action_just_pressed("left"):
	direction = Vector2.LEFT
elif Input.is_action_just_pressed("right"):
	direction = Vector2.RIGHT
elif Input.is_action_just_pressed("forward"):
	direction = Vector2.UP
elif  Input.is_action_just_pressed("back"):
	direction = Vector2.DOWN
	
if direction == Vector2.RIGHT:
	$AnimatedSprite.play("Rwalk")
	
	

move_and_slide()

This error seems to be from accidentally using = instead of : for the type declaration

var direction : Vector2 = (get_global_sprite_position() - global_position).normalized()

You can read more about static typing here

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.