# Moving figures in z-coordinate (z-axis)

**URL:** <https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310>\
**Category:** Coding Questions\
**Created:** [May 26, 2020, 1:15pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310 "2020-05-26T13:15:29Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 28, 2020, 2:05pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/21 "2020-05-28T14:05:25Z")

</div>

There’s again a problem…the camera should be more closer to the player… it’s very far…  
Please tell how can I do such

---

<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 28, 2020, 3:24pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/22 "2020-05-28T15:24:03Z")

</div>

That’s also the z value. Make it bigger

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 28, 2020, 4:38pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/23 "2020-05-28T16:38:02Z")

</div>

Thanks…  
It worked

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 29, 2020, 3:34am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/24 "2020-05-29T03:34:51Z")

</div>

Sir,please also tell how can I make my player move left or right when the device is tilted

---

<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 29, 2020, 4:11am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/25 "2020-05-29T04:11:51Z")

</div>

Left and right would be change of x in translate command

No idea about tilt

Use keys

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 29, 2020, 4:14am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/26 "2020-05-29T04:14:18Z")

</div>

Ok  
One more thing…  
How can I make obstacles appear in the way of the player, which the player could move aside and avoid hitting them?

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 29, 2020, 6:46am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/27 "2020-05-29T06:46:51Z")

</div>

[https://editor.p5js.org/Nis\_Collect/sketches/hqNc\_rtFI](https://editor.p5js.org/Nis_Collect/sketches/hqNc_rtFI)

Here’s my code but there’s only obstacles which changes its place.  
I need more obstacles, like they apper in some games.

---

<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 29, 2020, 10:18am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/28 "2020-05-29T10:18:38Z")

</div>

I have no idea

Chrisir

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 29, 2020, 11:13am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/29 "2020-05-29T11:13:26Z")

</div>

😞…  
Please try sir, please ask someone if you can.  
I am a beginner and also I don’t know anyone who can answer me  
except you and other over this forum

---

<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 29, 2020, 11:31am UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/30 "2020-05-29T11:31:09Z")

</div>

You have to do some work and cannot ask everything here…

Look at tutorials about arrays

- see [https://www.processing.org/tutorials/arrays/](https://www.processing.org/tutorials/arrays/)

and examples about movement

- see [https://www.processing.org/examples/](https://www.processing.org/examples/)

---

<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 29, 2020, 2:42pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/31 "2020-05-29T14:42:50Z")

</div>

here the obstacle is resetted every time it leaves the screen. You only have ONE obstacle but it reappears again and again.

You can steer the player with

- the a key - right
- d key - left
- s key stop

```auto

var zplane = -500;
var zob = -300;
var Tobx;
var playerX = 0;

function setup() {
  createCanvas(500, 500, WEBGL);
  avoidClipping();
}

function draw() {
  background(220);
  // translate(-width,-height);

  if(zob>300) {
   zob = -300;
   Tobx = random(-110, 110);
  }
  
  { // obstacle
    push();
    translate(Tobx, 60-30, zob);
    fill(255);
    stroke(0);
    box(60, 60, 60);
    pop();
  }

  push();
  translate(0, 60, zplane);
  fill(0);
  box(500, 20, 120000); // floor 
  pop();

  fill(250, 1, 5); // RED / player 
  translate(playerX, 50, 200 + 10 * 5);
  box(55, 65, 55);

  stroke(255);

  zob += 2;
  zplane += 2; //5;
  
  if(key=='a') 
      playerX-=2; 
  if(key=='d') 
      playerX+=2; 
  if(key=='s') 
      playerX+=0;   
}

function avoidClipping() {
  // avoid clipping (at camera): 
  // https : // 
  // forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
  perspective(PI / 3.0, width / height, 1, 1000000);
} //func

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 29, 2020, 3:19pm UTC](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310/32 "2020-05-29T15:19:16Z")

</div>

> [@Nis](#):
>
> Please try sir, please ask someone if you can.  
> I am a beginner and also I don’t know anyone who can answer me  
> except you and other over this forum

Consider becoming an [autodidact](https://en.wikipedia.org/wiki/Autodidacticism). 🙂

One of the best tools in a programmers tool chest is knowing the resources available to you and learning to navigate them.

This is a very short list:

> **Resources \< Click here to expand !**
>
> I encourage you to review the resources available here:
> 
> - The Processing _website_ has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - The Processing PDE (IDE) has lots to offer!  
> An exploration of the tabs will reveal what is available; libraries, tools and local examples there.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> - The source code can give insight if you are adventurous:  
> [GitHub - processing/processing: Source code for the Processing Core and Development Environment (PDE)](https://github.com/processing/processing)  
> Many of the Processing functions are here:  
> [processing/core/src/processing/core/PApplet.java at master · processing/processing · GitHub](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java)
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.
> - And the Internet. `:)`

`:)`

[Previous page](https://discourse.processing.org/t/moving-figures-in-z-coordinate-z-axis/21310.md?page=1)
