Discord
Login
Community
DARK THEME

Code help

the 12.5 is the player height divided by 2 and mapcol is the map where I drew the collision points

camera = class
  constructor = function(x,y,location)
    this.x = x
    this.y = y
    this.location = location
  end
  
  draw = function()
    screen.drawMap( "mapcol", this.x-199.5, this.y, 400, 400 )
    screen.drawMap( "mapcol2", this.x+199.5, this.y, 400, 400 )
    screen.drawMap( "map", this.x-199.5, this.y, 400, 400 )
    screen.drawMap( "map2", this.x+199.5, this.y, 400, 400 )
  end
  
  update = function()
    this.old_x = this.x
    this.old_y = this.y
    if keyboard.W then
      this.y -=1
      if mapHit(this.x,12.5,"mapcol") then
        print("hi")
        this.y+=1
      end
    elsif keyboard.A then
      this.x += 1
    
    elsif keyboard.S then
      this.y += 1 
    
    elsif keyboard.D then
      this.x -= 1
      
    end
  end
end

I got you bro:

https://microstudio.io/i/Tiberius2/fixyourcode/

@Tiberius2 I'm just moving the camera not the player so if I use y it says the y of the camera and its not based on the actual screen but the top of the player is at y=12.5 and the bottoms at -12.5 that's why I was doing that so your code would theoretically work if I was moving the character not the screen

alright I made a template for you just click on the link I sented you

will you update my code to fix collision im kinda stupid so i dont really understand how but i think the screentranslation is cool so ty for that

NVM ty for your help it turns out the problem was actually with the mapHit function so I fixed that

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community