Trying to access variable gravity in this script
extends KinematicBody2D
class_name Actor
export var speed: = Vector2(300.0, 1000.0)
export var gravity = 3000.0
var velocity: = Vector2.ZERO
func _physics_process(delta: float) -> void:
velocity.y += gravity*delta
#velocity.y = max(velocity.y, speed.y)
velocity = move_and_slide(velocity)
from this script
extends Actor
func _physics_process(delta: float) -> void:
var direction = Vector2(
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),0.0
)
velocity =
I get the error Unexpected token: Identifier:velocity
am I using class_name incorrectly?
You can access both velocity
and gravity
variables from base class, but you need to do it within a function, e.g.:
extends Actor
func _physics_process(delta: float) -> void:
velocity += Vector2.ZERO # just an example