skip to content
Scalable Hacker Blog

Search

Turret Allignment(Practice 3)

Less than one minute read Updated:
Assignment 3

Applying the game concepts (Collision, Raycast, Vector Dot & Cross products)

This is part of Math for Game Devs by Freya Holmér

Interactive Demo

42

Requirements Coverted to Three.js & R3F

  • a
    • Write code for placing and aligning a turret on a surface in front of the player, similar to how you would place a turret in an FPS game like TF2 or Overwatch
    • Make a simple turret using primitives, and make sure its topmost parent object is at the bottom of the turret for easy placement
    • You can use a simple raycast from a camera, and place the turret in OnDrawGizmos to make the assignment easier to test
    • Remember all the tools and vectors you have available, both on the raycast hit as well as on the camera itself!
  • b
    • You also need to fix a bug that freya your coworker introduced! The turret seems to be tilted sideways when there’s a sideways slope relative to the camera - it doesn’t actually always point forwards. Why is that? And how would you fix it? The turret is pointing a little bit to the right Note how the blue vector of the turret isn’t pointing in the same direction as the camera, when viewed from above

Code

GitHub