Pls help (10 c)

I’m making a game but I cant Macke a wall

could you perhaps provide slightly more info as to what you are doing? it’d be really helpful to determine how we can help you make a wall of any sort.

like, are you making a platformer? car game? is there gravity?

Easy:

// wall default script
if(!project.walls)
  project.walls = Object.create(null);

project.walls[this.uuid] = this;

// player update script
const lastX = this.x, lastY = this.y;

// movement...

const touchingAnything = Object.values(project.walls).filter(c => this.hits(c)).reduce((acc, cur) => cur || acc);

if(touchingAnything) {
  this.x = lastX;
  this.y = lastY;

This code does:

  1. Save the last ‘good’ position
  2. Movement code (you know how to do that)
  3. Calculate if touching anything
  4. If actually touching anything, revert to last ‘good’ position

what??? :sob: @noobfield really is a wizard, i didnt even know that was possible…

The object created in the wall script was a Object.create(null). In a nutshell, it just prevents default methods included with the Object prototype (prototypes are weird)

The array sequence is simple:

  1. Get an array with project.walls's values (Object.values(project.walls))

  2. Make a new array with the values ran through a function, which in this case does a this.hits(that) (.map(clip => this.hits(clip))) I misspelled it as .filter in the post, filter will only include values which the function returns true

  3. Reduce the array of boolean values into a single boolean value (.reduce((reducing, current) => current || reducing) .reduce is really weird but also really good

thanks soo much! now my game works

I promise I don’t know the movement part I was first starting whith the gravity and stuff pls heeelllp

for movement? what kind of movement fo you need? for really simple movement, without gravity, just copy the code from the builtin asset. you can also use

  if(isKeyDown("left")) {
        this.vx -= this.speed;
    }
    if(isKeyDown("right")) {
        this.vx += this.speed;
    }
    if(isKeyDown("up")) {
        this.vy -= this.speed;
    }
    if(isKeyDown("down")) {
        this.vy += this.speed;
    }
    //movement 
    this.x += this.vx;
    this.y += this.vy;
    this.vx *= 0.96;
    this.vy *= 0.96;

initialize vx and vy to zero, and speed to whatever. i used 0.4. this makes for really smooth, satisfying motion. if there’s gravity, use a vx and vy system where you change vy each tick to make you fall, and set the vy to a negative integer to jump. then change vx to move horizontally. i hope this helps!

Also remember to Math.min(this.vx, this.maxSpeed), or you’ll keep going faster and faster and faster… BIG RIGS: Over The Road Racing has this problem, the speed at which you go back isn’t capped but is for going forward.

thanks, really

oh, i didnt know you could do that… i just did

if(this.vy <= this.whatever) {
[movement code here]
}