# How can I make an object remain in the x position it was fired from?

**URL:** https://discourse.processing.org/t/how-can-i-make-an-object-remain-in-the-x-position-it-was-fired-from/30187
**Category:** Coding Questions
**Created:** [May 20, 2021, 10:11am UTC](https://discourse.processing.org/t/how-can-i-make-an-object-remain-in-the-x-position-it-was-fired-from/30187 "2021-05-20T10:11:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![burritonacho](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@burritonacho](https://discourse.processing.org/u/burritonacho)
#### Post date: [May 20, 2021, 10:11am UTC](https://discourse.processing.org/t/how-can-i-make-an-object-remain-in-the-x-position-it-was-fired-from/30187/1 "2021-05-20T10:11:27Z")

</div>

I have a character moving back and forth across the screen that fires a projectile, and I want the projectile to stay on screen.

The Y position part of my code is working, but I cannot get my projectiles to stay in the X position that they were launched from using a mousePress.

Does anybody have any tips on how to achieve this?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 20, 2021, 11:57am UTC](https://discourse.processing.org/t/how-can-i-make-an-object-remain-in-the-x-position-it-was-fired-from/30187/2 "2021-05-20T11:57:25Z")

</div>

Hello!

The idea is to have separate variables for the x position of the character and of the projectile - because they are not the same but express different things!

Therefore you need `float characterX` AND `float projectileX`

upon firing, make sure to say `projectileX=characterX;` // copy the current character pos X

- when displaying the projectile use projectileX

- when displaying the character use characterX

Hey, and welcome to the forum, great to have you here!

Chrisir
