I’m following a series of tutorials and have been trying to convert them from C# script into visual scripts.
The tutorials are found at this link.
I’m a novice, and am using Visual Scripting as a way to wrap my mind around c#.
How would I go about turning this set of instructions into a visual script? The parts that are really blowing my mind are bolded and red, but I went ahead and put more than strictly necessary for the sake of context.
No Wall Jumping
Allowing a jump when touching anything means that we could also jump when in the air but touching a wall instead of the ground. If we want to prevent that we have to be able to distinguish between the ground and something else.
It makes sense to define the ground as a mostly horizontal plane. We could check whether what we’re colliding with satisfied this criteria by inspecting the normal vector of the contact points of the collision.
brilliantlongdartfrog
We can get the collision information by adding a Collision parameter to both OnCollisionEnter and OnCollisionStay. Instead of directly setting onGround to truewe’ll forward that responsibility to a new EvaluateCollision method, passing it the data.
void OnCollisionEnter (Collision collision) {
//onGround = true;
EvaluateCollision(collision);
}
void OnCollisionStay (Collision collision) {
//onGround = true;
EvaluateCollision(collision);
}
void EvaluateCollision (Collision collision) {}
The amount of contact points can by found via the contactCount property of Collision. We can use that to loop through all points via the GetContact method, passing it an index. Then we can access the point’s normal property.
void EvaluateCollision (Collision collision) {
for (int i = 0; i < collision.contactCount; i++) {
Vector3 normal = collision.GetContact(i).normal;
}
}
The normal is the direction that the sphere should be pushed, which is directly away from the collision surface. Assuming that it is a plane, the vector matches the plane’s normal vector. If the plane were horizontal then its normal would point straight up, so its Y component should be exactly 1. If this is the case then we’re touching the ground. But let’s be lenient and accept Y components that are 0.9 or greater.
Vector3 normal = collision.GetContact(i).normal;
onGround |= normal.y >= 0.9f;
Any help is appreciated! I’m making loads of progress with learning, but I’m not quite sure what this tutorial is asking me to do in this step.