This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

When I try to move my player an error shows that says this "Invalid operands in Vector 2 and string in operator '*' ". I marked the sentence where the error is. I don't know what to do.

extends Area2D

export var speed = '400'
var screen_size

func ready():
size = getviewportrect().size

func process(delta):
var velocity = Vector2()
actionpressed ("uiright"):
velocity.x += 1
if Input.isactionpressed ("uileft"):
velocity.x -= 1
velocity.y -= 1
if Input.isactionpressed("ui_down"):
velocity.y += 1
if velocity.length() > 0:
***velocity = velocity.normalized() * speed***

position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)
in Engine by (15 points)

1 Answer

+2 votes
Best answer

Because you set speed = '400' you've made speed be a String, not a number. Remove the quote marks.

by (22,191 points)
selected by

Thanks, now it works

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.