# Adding velocity to a character

**URL:** <https://forum.makecode.com/t/adding-velocity-to-a-character/458>\
**Category:** Arcade\
**Created:** [August 19, 2019, 3:21pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458 "2019-08-19T15:21:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomisOps](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TomisOps](https://forum.makecode.com/u/TomisOps)\
**Post date:** [August 19, 2019, 3:21pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/1 "2019-08-19T15:21:15Z")

</div>

Hello, its me again, im trying to add 15 speed to my character every time it overlaps with the pizza, but the speed doesnt change at all.Any help?  
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {  
info.changeScoreBy(1)  
movx += movx + 15  
movy += movy + 15  
controller.moveSprite(mySprite, movx, movy)  
info.startCountdown(timer)  
pizza.setPosition(Math.randomRange(20, 140), Math.randomRange(20, 100))  
})  
let timer = 0  
let pizza: Sprite = null  
let mySprite: Sprite = null  
let movx = 0  
let movy = 0  
movy = 75  
movx = 75  
scene.setBackgroundColor(11)  
mySprite = sprites.create(img``, SpriteKind.Player)  
controller.moveSprite(mySprite, movx, movy)  
pizza = sprites.create(img``, SpriteKind.Food)  
timer = 3

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [August 19, 2019, 3:31pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/2 "2019-08-19T15:31:17Z")

</div>

If you want to _change_ `movx` and `movy` by 15 each time, then the syntax that you want is

```auto
movx += 15
movy += 15

```

Keep in mind that `controller.moveSprite` merely changes the speed at which the sprite moves when they’re operated by the controller. If you want to change the actual velocity of the sprite (i.e. you want the sprite to be moving all the time), then you want this instead:

```auto
mySprite.vx += 15
mySprite.vy += 15

```

Without seeing your game, I’m not sure which of the two you need.

---

<div class="post-metadata">

**Author:** ![TomisOps](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TomisOps](https://forum.makecode.com/u/TomisOps)\
**Post date:** [August 19, 2019, 3:35pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/3 "2019-08-19T15:35:09Z")

</div>

Thanks for the help, I have already tried doing your first example, but it doesnt seem to work, and yes, i want to change the speed at which the sprite moves when i press the keys. I have no idea what to do.

---

<div class="post-metadata">

**Author:** ![TomisOps](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TomisOps](https://forum.makecode.com/u/TomisOps)\
**Post date:** [August 19, 2019, 3:37pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/4 "2019-08-19T15:37:54Z")

</div>

What i can tell by using the debug mode, is that the variable does go up, but not the characters speed

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [August 19, 2019, 4:19pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/5 "2019-08-19T16:19:14Z")

</div>

Give this a try, so that you can see how the different speeds behave:

> **[Sprite Controller Speed](https://arcade.makecode.com/70222-15694-41222-26360)**
>
> Made with ❤️ in MakeCode Arcade.

Press A to increase the speed, and press B to decrease the speed. Move the sprite with the arrow keys. The score reflects the current speed.

Your initial speed is set to 75, which is already pretty high. Changing the speed by 15 when it’s that high might not be very noticeable.

---

<div class="post-metadata">

**Author:** ![TomisOps](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TomisOps](https://forum.makecode.com/u/TomisOps)\
**Post date:** [August 19, 2019, 6:52pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/6 "2019-08-19T18:52:35Z")

</div>

Thanks!! it works great now, thank you

---

<div class="post-metadata">

**Author:** ![Buller](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@Buller](https://forum.makecode.com/u/Buller)\
**Post date:** [February 5, 2021, 4:29pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/7 "2021-02-05T16:29:25Z")

</div>

Thanks helped me as well! Just wondering why do you need to set the movement again for each button A&B when it’s already in On Start: Move My Sprite with buttons vx (mySpeed) xy (mySpeed)?

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [February 25, 2021, 7:16pm UTC](https://forum.makecode.com/t/adding-velocity-to-a-character/458/8 "2021-02-25T19:16:02Z")

</div>

Hi, @Buller !

Sorry about the delay in my response. I haven’t been able to hop on the forum in a couple of months.

We’re changing the variable `mySpeed` each time a button is pressed. The sprite’s velocity, though, doesn’t change just because `mySpeed` changes. They’re not linked in any way. If we want to change the sprite’s velocity, we need to say so in our code. That’s why the blocks are repeated.
