Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Richard_A_Odell |
var velocity = Vector2()
const GRAVITY = 35
const SPEED = 180
const SWIM_SPEED = 192
const JUMPFORCE = -1164
const SPRING = -1280
onready var is_swimming = false
func _physics_process(delta):
velocity.y = velocity.y + GRAVITY
# get Movement(left and right and jump)
if Input.is_action_pressed("move_right"):
if is_swimming == true:
velocity.x = SWIM_SPEED
else:
velocity.x = SPEED
$Sprite.flip_h = false
if Input.is_action_pressed("move_left"):
if is_swimming == true:
velocity.x = -SWIM_SPEED
else:
velocity.x = -SPEED
$Sprite.flip_h = true
if Input.is_action_pressed("move_up"):
if is_swimming == true:
velocity.y = -SWIM_SPEED
else:
velocity.y = -SPEED
if Input.is_action_pressed("move_down"):
if is_swimming == true:
velocity.y = -SWIM_SPEED
else:
velocity.y = SPEED
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMPFORCE
velocity = move_and_slide(velocity, Vector2.UP)
velocity.x = lerp(velocity.x, 0, 0.1)
#if player jumps on to a Spring
func _on_Spring_body_entered(body):
velocity.y = SPRING
func bounce():
velocity.y = JUMPFORCE * 0.7
func ouch():
set_modulate(Color(1, 0.3, 0.3, 0.4))
velocity.y = JUMPFORCE * 0.5
that works but i need to change func ouch(): to func ouch(var enemypos.x)
the var enemypos.x is giving me the error