Home Game Development vector – Understanding use of dot product in pace increase pad

vector – Understanding use of dot product in pace increase pad

0
vector – Understanding use of dot product in pace increase pad

[ad_1]

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

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

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 does not drop beneath zero, however I’d advocate this to keep away from getting a lift backward should you drive throughout the pad the opposite method (except you need a bi-directional race of some type).

Note that since we normalized the pad’s vector to a unit vector path first, we have taken its size out of the dot product equation, leaving $textual content{boostFactor} = | textual content{automotive.velocity} | cos(theta)$

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}$$

Here the size of the pad’s increase vector represents a multiplier on the incoming velocity: a size of 1 means your additional increase is 100% of your incoming velocity should you match the pad path completely. A size of 0.5 means you may get an additional 50% of your incoming velocity, and so on.

Doing it this fashion, the rate change is all the time pointing within the path of the pad, so should you drive throughout it at a diagonal, you may get a nudge to redirect you ahead in accordance with the pad’s path, serving to you keep on-track even should you veered sideways shortly to catch the increase pad. (I selected to indicate this fashion as a result of anecdotally, that is the behaviour I’m used to seeing in racing video games – although it has been a whiles since I performed this explicit Mario Kart so I do not recall whether or not that is how they do it)

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

Note that it is a good instance for displaying the type of factor we’d use dot merchandise for, nevertheless it’s seemingly not precisely how Mario Kart or different racers implement their boosts. Just a few concerns we would usually apply when fleshing this out to an actual recreation function:

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

    So in apply, video games will usually “bucket” the angle into coarser wedges. Say you get a 100% increase should you’re aligned inside 5 levels, and a 75% increase should you’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 bounce within the impact (and sounds/visuals we use) moderately 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 immediately because the increase issue.

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

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

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

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

    Say this increase pad is on a bounce to the following 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 most likely 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 bounce and it seems to be like the sport cheated them!

    So for this sort of increase pad, we would usually make it give a hard and fast quantity of additional velocity over a spread of speeds, so should you hit it wherever inside this tolerance zone you get the total increase you anticipate. (Though this “full increase quantity” might nonetheless depend upon 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 should be carried out. Like any recreation mechanic, there are many alternative ways we will select to implement it to get completely different results.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here