# How to multiply motion.y?

Attention Topic was automatically imported from the old Question2Answer platform.

Hi, I’m working on a 2d platformer. I want for the player to stop moving up when the player releases the jump button.

This is the code

``````extends KinematicBody2D

var motion = Vector2()
var airjump = 0.2
var airtime = 0.2
const MOE = 0.2
const CTIME = 0.2
const SPEED = 300
const GRAVITY = 60
const JUMPHEIGHT = -700
const UP = Vector2(0,-1)
const CUTJUMPHEIGHT = 0.1

#move right and left whenthe arrow keys are presed
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
else:
motion.x = 0

#Timer to dimtermine if the player inputed the jump button recently
airjump -= get_process_delta_time()
if Input.is_action_just_pressed("ui_up"):
airjump = CTIME
#Timer to see if the player was on the floor recently
airtime -= get_process_delta_time()
if is_on_floor():
airtime = MOE

#Tells the game to jump if both timers are good with jumping
if airjump > 0 && airtime > 0:
motion.y = JUMPHEIGHT

#Make the player stop moving upwards when the jump button is released
if Input.is_action_just_released("ui_up"):
if motion.y > 0:
motion.y * CUTJUMPHEIGHT

motion = move_and_slide(motion, UP)
pass
``````

motion.y += JUMPHEIGHT has been changed to motion.y = JUMPHEIGHT

TheAsker | 2018-11-04 17:57

Then maybe you should edit your question to avoid confusion.

SIsilicon | 2018-11-04 18:22