Week 2


2.1: Dangerous Spikes

Spikes

  • Before we add moving dangerous things (enemies), we’ll add dangerous things that don’t move (spikes)
  • Place spikes in props layer

  • Add script
  • When level starts, set immovable true
  • When touched get toucher
  • If toucher has tag player (make sure player has player tag)
  • Restart current level

 

3: Enemy NPC that chases you

  • Make new layer for NPCs
  • Place an enemy NPC somewhere near your player

  • Add script to NPC
  • Constantly
  • Create a new function definition named Charge
  • Use the function call in constantly
  • Play to test (save script)
  • Charge does nothing
  • Charge: Set x velocity to 100
  • Set y velocity to 100
  • Play
  • We want velocities to be towards us so we need difference between position of NPC and position of player.

  • Close NPC script and edit player script
  • When level starts
  • add player tag

  • Open NPC script
  • Remove hardcoded numbers
  • X position of first instance by tag player - x position of myself
  • Y position player - y position myself
  • Play test

 

4: Vision limit for NPC

Only charge if distance to player is less than 200

  • Constantly, if
  • Distance from myself to instance other (starts as angle from)
  • Remove other, use first instance by tag player
  • Less than 200
  • Note: if you’re not sure what your maths is doing or what your numbers are, you can log them using the log block and debug mode

 

⚡ Bonus Activities ⚡


Bonus 2.1: Limiting the camera

 

Bonus 2.2: Triggering spikes with a switch

 

results matching ""

    No results matching ""