Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | 4181 |
I have a vector defined as export var velocity:=Vector2(0.0,0.0)
after putting the code through things to get the Kinematicbody2d I try and use velocity=move_and_slide(velocity,UP_DIRECTION) and it says it’s an integer.
const UP_DIRECTION:=600
export var speed=100.0
export var jump_str=100.0
export var maximum_jumps=100.0
export var extra_jump_str=100.0
export var gravity=100.0
export var jumps_made:=0
export var velocity=Vector2()
func physicsprocess(delta: float) -> void:
var horizontal_direction=(Input.getactionstrength("ui.right")-Input.getactionstrength("ui.left"))
velocity.x=horizontal_direction*speed
velocity.y+=gravity*delta
var falling=velocity.y>0.0 and is_on_floor()
var jumping=Input.is_action_just_pressed("ui.select") and is_on_floor()
var extra_jumping=Input.is_action_just_pressed("ui.select") and falling
var jump_canceled=Input.is_action_just_released("ui.select") and velocity.y<0
var idling= is_on_floor() and is_zero_approx(velocity.x)
var running= is_on_floor() and not is_zero_approx(velocity.x)
if jumping:
jumps_made+=1
velocity=-jump_str
elif extra_jumping:
jumps_made+=1
if jumps_made<=maximum_jumps:
velocity.y+=-extra_jump_str
elif falling:
velocity.y=0.0
velocity.normalized()
move_and_slide(velocity,UP_DIRECTION)