Moving figures in z-coordinate (z-axis)

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

1 Like

That’s also the z value. Make it bigger

2 Likes

Thanks…
It worked

1 Like

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

Left and right would be change of x in translate command

No idea about tilt

Use keys

1 Like

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?

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.

I have no idea

Chrisir

:disappointed:
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

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

Look at tutorials about arrays

and examples about movement

1 Like

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



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

Consider becoming an autodidact. :slight_smile:

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:

:)

2 Likes