vector – Understanding use of dot product in pace increase pad

vector – Understanding use of dot product in pace increase pad

[ad_1]

It sounds just like the creator envisions the mechanic working one thing like this:

Vector3 boostDirection = Vector3.Normalize(pad.boostVector);
float boostFactor = Vector3.Dot(boostDirection, automotive.Velocity);

boostFactor = Mathf.Max(boostFactor, 0);

Vector3 velocityChange = pad.boostVector * boostFactor;
// Equivalently:
// velocityChange = new Vector3(
//                     pad.boostVector.x * boostFactor,
//                     pad.boostVector.y * boostFactor,
//                     pad.boostVector.z * boostFactor
//                );

automotive.velocity += velocityChange;

They do not explicitly state that the increase issue ought to be clamped so it would not drop beneath zero, however I would suggest this to keep away from getting a lift backward if you happen to drive throughout the pad the opposite manner (until you desire a bi-directional race of some type).

Notice that since we normalized the pad’s vector to a unit vector route first, we have taken its size out of the dot product equation, leaving $textual content{boostFactor} = | textual content{automotive.velocity} | cos(theta)$, the place $theta$ is the angle between the automotive’s route of movement and the increase pad’s route.

So then after we multiply this scalar by the unique increase vector, we re-introduce that vector’s size, getting a complete velocity change with magnitude:

$$start{align}
| textual content{velocityChange} | &= | textual content{pad.boostVector}|| textual content{automotive.velocity} | cos(theta)
&= textual content{pad.boostVector} cdot textual content{automotive.velocity}
finish{align}$$

Right here the size of the pad’s increase vector represents a multiplier on the incoming velocity: a size of 1 means your further increase is 100% of your incoming velocity if you happen to match the pad route completely. A size of 0.5 means you may get an additional 50% of your incoming velocity, and so forth.

Doing it this manner, the rate change is at all times pointing within the route of the pad, so if you happen to drive throughout it at a diagonal, you may get a nudge to redirect you ahead in keeping with the pad’s route, serving to you keep on-track even if you happen to veered sideways rapidly to catch the increase pad. (I selected to indicate this model as a result of anecdotally, that is the behaviour I am used to seeing in racing video games – although it has been some time since I performed this specific Mario Kart so I do not recall whether or not that is how they do it)

You would as an alternative select to normalize the rate, not the increase vector, and multiply the rate by the increase issue to get the rate change. That might offer you a lift pad that sill provides you an identical magnitude of additional velocity, however preserves your incoming route: drive throughout the pad diagonally, and you will be accelerated diagonally.

Notice that it is a good instance for exhibiting the sort of factor we would use dot merchandise for, but it surely’s seemingly not precisely how Mario Kart or different racers implement their boosts. Just a few issues we might usually apply when fleshing this out to an actual recreation characteristic:

  • Effective-grained levels of success relying on how completely you match the pad’s angle can really feel inconsistent to the participant. You will nearly by no means get the proper 0-degree-deviation 100% increase.

    So in apply, video games will usually “bucket” the angle into coarser wedges. Say you get a 100% increase if you happen to’re aligned inside 5 levels, and a 75% increase if you happen to’re aligned inside 45 levels. This helps with the perceived consistency, and gamers can clearly really feel the distinction between hitting the increase “completely” and “nearly” as a result of there is a discrete leap within the impact (and sounds/visuals we use) relatively than a clean gradient of intermediate levels.

    We’ll nonetheless use dot merchandise to compute your alignment and discover the right bucket, we simply will not use the dot product instantly because the increase issue.

  • Equally, we’ll usually have a extra restrictive tolerance for what’s wanted to activate the increase. With the mannequin within the instance, if you happen to drive throughout the pad at an angle of 89 levels to its route, you continue to get a lift.

    Many video games will set the next tolerance earlier than you hit the “minimal increase” bucket, so it’s important to be travelling at most 45-60 levels from the pad’s route for it to activate.

  • We’ll normally implement a most pace, in order that hitting a sequence of boosts would not multiply your pace exponentially and rocket you out of the extent totally.

  • We’ll usually “bucket” the rate change too, much like how we bucket the angles, for comparable consistency causes.

    Say this increase pad is on a leap to the subsequent phase of observe, and the participant simply landed it on their earlier lap. This time, they hit the identical increase pad however with 5% much less incoming pace. The participant in all probability cannot understand that they did something in another way this time, but when we use the method above and provides them 5% much less increase, they find yourself lacking the leap and it appears to be like like the sport cheated them!

    So for one of these increase pad, we might usually make it give a set quantity of additional velocity over a variety of speeds, so if you happen to hit it wherever inside this tolerance zone you get the complete increase you count on. (Although this “full increase quantity” may nonetheless rely on which automotive you are utilizing)

So take this instance for what it’s: a strategy to illustrate a scenario the place dot merchandise are helpful, however not as a prescription for a way increase pads have to be carried out. Like every recreation mechanic, there are many other ways we will select to implement it to get completely different results.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply