Math for Game Developers - Backstabbing Part 2

Поділитися
Вставка
  • Опубліковано 26 жов 2024

КОМЕНТАРІ • 61

  • @varuntyagi6116
    @varuntyagi6116 11 років тому +33

    "Now I'm gonna go behind and see if our dot product is working for..oh..okay I think its working" hahahahaha

  • @daywalkertpify
    @daywalkertpify 4 роки тому +3

    Seven years since creation of this video tutorial but still very helpful and adoptable to the game development today. Thank you very much for this great content!

  • @charlie12486
    @charlie12486 2 роки тому +2

    I watched all of your videos and now i see this a signal of life from a legend

  • @CoffeeOverdosed
    @CoffeeOverdosed 5 років тому +3

    Omg that visual representation was so on point with the lesson hahahaha!! "I think it worked" was the best reaction

  • @To-mos
    @To-mos 6 років тому +3

    This is an insanely simple solution to the problem. I did this through localizing the player offsets from one another to their perspective by subtracting their world transformation and using atan2 to figure out if they were looking at one another or away. This also allowed for solving who was looking at who. Now I'm gonna replace it all using this :D

  • @JorgeVinoRodriguez
    @JorgeVinoRodriguez  11 років тому +2

    Thanks! Glad I could help! Most of the videos have example code, the best way to learn is to try it out.

  • @unity6926
    @unity6926 2 роки тому +2

    Holy crap you're back!!!! Awesome

    • @walker-snow
      @walker-snow 2 роки тому

      Some comments are really old. I doubt it's a new video.

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  2 роки тому +1

      I appreciate the excitement but no, I just made a previously private video public :)

  • @omg_look_behind_you
    @omg_look_behind_you 2 роки тому +1

    wow bro, I've missed your videos so much. I always considered you the Khan academy of math for game development. Hope we will be seeing more of you and all is right on your end of the world.

    • @mreazl6227
      @mreazl6227 2 роки тому +1

      this isn't a new video, check other comments

  • @maschill92
    @maschill92 11 років тому +12

    "I think it worked." HAHAHA!!!

  • @tjhaskelh96
    @tjhaskelh96 11 років тому

    ah ok. Great videos! Just finished my linear algebra class and intro to comp sci class (scheme). I really want to get in to game development so it's really cool to watch these and at least get some perspective on how the math is translated to code even though I don't know too much syntax yet.

  • @sweatyeti
    @sweatyeti 9 років тому +2

    Hey, thanks so much for this video. This is a neat technique!
    Since I've read it's nice to avoid using square root operations when programming, is there a way to avoid this when normalizing the "blue-red" vector?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  9 років тому +3

      +sweatyeti If you only care about whether something is completely behind something else then you don't have to do any normalization. If the dot product is negative the vectors point in opposite directions (less than 90 degrees), and positive in the same direction. But remember, in this particular case the code is only called once in a while (if you think about it, compared to everything else games have to do, this particular dot product doesn't occur very often, once every few frames at best) so the impact on performance is minimal. Check out the Amdahl's Law video and the rest of the optimization series for a deeper explanation of that. But you use dot product a lot for other stuff as well and in those cases it's usually straightforward to avoid sqrt() by e.g. precomputing.

    • @sweatyeti
      @sweatyeti 9 років тому +1

      Jorge Rodriguez
      Thanks so much for the quick and thorough response. For better or for worse (probably for worse), I'm always keen to optimization opportunities, but you make a good point about how situational this event is.
      I'll check out Amdahl's Law and learn more about better optimization habits.

  • @joysaha3927
    @joysaha3927 2 роки тому +1

    Please make more videos like this man! :)

  • @mohammedgoder
    @mohammedgoder 2 роки тому +1

    Damn, its been a while since you've posted.

  • @julianaskuratovsky8701
    @julianaskuratovsky8701 5 місяців тому

    super ultra amazing!!!

  • @RussellTeapot
    @RussellTeapot 6 років тому

    This series is amazing, explanations are crystal clear and essentially language agnostic (I'm following this in JavaScript with no problems), excellent job! I have a question: since for the dot product (d.p.) we use normalized vectors, is it wise to implement d.p. already with normalized vectors? What I mean is: instead of passing normalized vectors, I could pass the vector and "grab" the normalized version within the d.p. function, since I already implemented a getter for the normalized version of the vector. Or it's best to leave the d.p. as it is, since it can be used in other situations, in which "regular" (not normalized) vectors are used?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  6 років тому

      Thank you for the kind words :)
      I think your question is perceptive and shows that you've thought about the issue and you care about good code, so nice work there. There are many applications for dot product on non-normalized vectors (which I will cover in later parts of this series) so I would recommend you keep your dot product function to just do dot product.
      As a general rule, it can be a drawback if you create a function that does too much at once. You want to be helpful so you normalize vectors in your function, but the side effect is that if anyone wants only the dot product and not the normalizing they're up.a creek. On the upside, if you provide a dot product that only does dot product, then you can write something like:
      float AngleBetweenTwoVectors(vec3 a, vec3 b) { return dot(normalize(a), normalize(b)); }
      and use that method if you like.

  • @CatzHoek
    @CatzHoek 2 роки тому +1

    I was ready to complain about the background noise but then saw saw this is a 8 year old video you just made available again. So maybe that´s okay.

  • @abandoned7501
    @abandoned7501 5 років тому

    very nice, why unlisted tho?

  • @theleopeople5771
    @theleopeople5771 Місяць тому

    I don't understand a thing... don't player and enemy in the final example face in the same direction? So it would mean that dot product should be 1, not -1
    What is it I'm missing here?!

  • @wasiimo
    @wasiimo 8 років тому

    After watching the vector collinearity with scalars videos on Khan Academy this makes a lot of sense. Making these normalized makes so is a great idea. Since the only time the red player's direction would be facing the same way as the blue player's direction is when the red player's length is 1 or -1. At first the dot product equation seemed rather bizarre to me but now it makes a lot of sense. By the way did you ever cover atan2?

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      +fun Tertain I think I may have talked about atan2 in the mouse control video.

    • @wasiimo
      @wasiimo 8 років тому

      Jorge Rodriguez You never did

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      +fun Tertain Oops sorry. Try www.cplusplus.com/reference/cmath/atan2/ and the wikipedia article.

  • @harrynewton4786
    @harrynewton4786 9 років тому

    Ok so just to clarify some things, so the normalize function is the calculation of the R-B/absolute(R-B)? and from there on the dot product equation takes those values and does the magic stuff.

  • @NonsensGaming
    @NonsensGaming 4 роки тому

    if i do this i have the problem that if i stand infornt of the enemy i get 0 and if i stand beheind the enemy i get 0 as well

  • @wasiimo
    @wasiimo 9 років тому

    This clicks so easily.

  • @ClimFreeFeelRain
    @ClimFreeFeelRain Рік тому

    3:57 when the code you think is not working actually works (too well)

  • @sweatyeti
    @sweatyeti 9 років тому +7

    I created a quick demo using this concept on KhanAcademy for those who are interested:
    www.khanacademy.org/computer-programming/demo-collision-facing-behind/5554809164398592

  • @ezetreezy
    @ezetreezy 8 років тому

    This may a bit off topic, but how would using the cross product to determine(what direction left or right) a main player needs to turn to see an enemy player. (assuming you have the position and facing vectors)(positive z in the up vector). Your videos rock btw.

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      If you have the direction vector that the player is facing and a direction vector to an enemy, the cross product of these will be perpendicular to both of them, so it will be up or down. Not sure that's what you want.
      If you want to figure out how to turn to see an enemy player, maybe you should use plain old simple angles. In other words, find an angle that describes the current rotation of the player in world coordinates, then another angle that describes the direction to the enemy in world coordinates, then subtract. Then you have a rotation angle that you can apply to your rotation.

    • @ezetreezy
      @ezetreezy 8 років тому

      Jorge Rodriguez Yeah thats what i thought. I was asked this by a professor and I did not know how to answer it using the Cross Product.

    • @ezetreezy
      @ezetreezy 8 років тому

      i believe this is the answer.
      //get cross between main player facing and up //vector
      Vector3 cross = mainPlayer.Facing.Cross(new Vector3(0,0,1));
      //get the vector from enemy to mainPlayer
      Vector 3 inBetween = new Vector3((enemy.Position.X - mainPlayer.Position.X, enemy.Position.Y - mainPlayer.Position.Y, enemy.Position.Z - mainPlayer.Position.Z);
      //compute the angle
      float dot = cross.dot(inBetween); if (dot

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      There should be some kind of vector subtraction procedure you can call instead of doing it manually like that. Also, there may be some kind of global constant for the up vector. Also, you may want to make a check or guard for when the player is facing directly up or down - this code will fail in those situations. Other than that, looks good. :)

    • @ezetreezy
      @ezetreezy 8 років тому

      Jorge Rodriguez Awesome. Thanks for the help.

  • @pascalampere6098
    @pascalampere6098 8 років тому

    So with 3D unit vectors if the dot product is negative that means the normalized vector br points to a point on the surface of the back half sphere of the view vector v?

  • @PETRUSAGOSTINHO
    @PETRUSAGOSTINHO Рік тому

    Where is the link of first part?

  • @smackerlacker8708
    @smackerlacker8708 7 років тому

    So.... what I've learned so far is.... Dot product good?

  • @johnwheel2591
    @johnwheel2591 2 роки тому

    Face stab is so true

  • @Xgamesvidoes
    @Xgamesvidoes 4 роки тому

    Hahaha! Great videos so far! :D

  • @Ark0Hak
    @Ark0Hak 5 років тому

    Hi in 2019 ). in the previous video you promised to show in the next video mario's source code.

  • @harrynewton4786
    @harrynewton4786 9 років тому

    did you normalize both objects? the Vector v and br?

  • @dogukanozdemir1914
    @dogukanozdemir1914 8 років тому

    Can someone please help me the output seems to give me 1 i dont understand why:
    Point player(3.0f, 0.0f);
    Vector playerDirection(2.0f, 0.0f);
    Vector normalizedPDirection = playerDirection.normalize();
    Point enemy(3.0f, 3.0f);
    Vector br = (enemy - player);
    Vector normalizebr = br.normalize();
    float Angle = getDotProductOf(normalizedPDirection, normalizebr);
    std::cout

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      NormalizedPDirection is playerDirection.normalize() = (2.0, 0.0).normalized() = (1.0, 0.0)
      normalizebr is br.normalize() = (enemy - player).normalize() = ((3.0, 3.0) - (3.0, 0.0)).normalize() = (0.0, 3.0).normalize() = (0.0, 1.0).
      The dot product of (1, 0) and (0, 1) should be 0. If you're getting 1 then your dot product must be different than mine.

    • @dogukanozdemir1914
      @dogukanozdemir1914 8 років тому

      Jorge Rodriguez
      this is how my dot product looks like but I'm still getting 1
      float getDotProductOf(const Vector & a, const Vector & b)
      {
      return (a.x * b.x + a.y + b.y);
      }
      just in case here is the whole code:
      pastebin.com/Zm22r9SZ

    • @dogukanozdemir1914
      @dogukanozdemir1914 8 років тому

      Just as I post my reply i saw the problem the "a.y + b.y" should be * not + lol thanks:D

    • @JorgeVinoRodriguez
      @JorgeVinoRodriguez  8 років тому

      :)

  • @JorgeVinoRodriguez
    @JorgeVinoRodriguez  11 років тому +2

    C++ :)

  • @tjhaskelh96
    @tjhaskelh96 11 років тому

    Is this in java?

    • @To-mos
      @To-mos 5 років тому

      C++ from the looks of it