UPB-Graphics / Beyond-Genesis-Client

Client for Beyond Genesis Project
MIT License
0 stars 22 forks source link

Add procedurally generated Spider prototype #7

Closed stery28 closed 3 years ago

stery28 commented 3 years ago

Addressed Issue

Primitive characters (#3)

Description of the change

A collection of scripts have been created in order to procedurally generate a Spider using primitives, exposing various parameters in order to configure its body size, number of legs, legs IK and legs movement animation. The legs are made of three parts/bones: UpperLeg, MiddleLeg and LowerLeg (representing the joints/pivots). The UpperLeg is attached to the body, and the LowerLeg is looking towards the IK target, ideally oriented parallel to the normal of the surface point targeted.

The hierarchy of the generated Spider GameObject should look like this (pseudo-JSON):

"Spider": {
     "Spine": {
         "Cube": "(main body)",
         "Sphere": "(head)",
         "Legs": [{
             "UpperLeg": {
                 "Cube": "(mesh)",
                 "MiddleLeg": {
                     "Cube": "(mesh)",
                     "LowerLeg": ["Cube"]
                 }
             }
         }]
     },
     "LegTargets": [ "GameObjects" ],
}

The elevation and rotation of the main body is done by rotating the Spine based on the mean position determined by the left and right legs, with respect to the mean up vector of each leg IK target (represented by the normal of the surface in each target point) for elevation, and with respect to the up vector resulted as a cross product between the vector from the left legs to the right legs and the forward vector of the main Spider object.

The joint between UpperLeg and MiddleLeg is rotated towards a hint represented by the UpperLeg's position translated by its up vector (although this might not be the best hint, but I tried to keep it simple). This is done by creating a plane having its origin in UpperLeg's position and the normal defined by LowerLeg-UpperLeg, then MiddleLeg and the hint are projected on the plane in order to determine the shortest angle between them and rotate the MiddleLeg joint around the plane's normal accordingly.

The following scripts were created:

In order to use this functionality, an empty GameObject must be created and the SpiderGenerator script should be attached to it, configuring the following properties:

Currently, the SpiderGenerator relies on pre-configuring the mentioned fields either using default values in the script or setting them from the editor. In order to better support the procedural generation idea of the game (so it can be used/triggered by another script, for example), the values could be set by reading a config file during the CreateSpider() method, or by creating a Init() method (similarly to how the other added scripts work) which acts like a constructor (taking the mentioned fields as required arguments) and executing the CreateSpider() method after the fields are set.

Release Notes: A new procedural Spider prototype have been added (#3).


Preview

Procedural Spider