Corgi Engine  v8.8
MoreMountains.CorgiEngine.SurfaceCrawler Class Reference
Inheritance diagram for MoreMountains.CorgiEngine.SurfaceCrawler:
MoreMountains.CorgiEngine.CorgiMonoBehaviour

Public Types

enum  Directions { Directions.Clockwise, Directions.CounterClockwise }
 the potential directions this object can move towards More...
 

Public Member Functions

virtual void ChangeDirection ()
 Call this method to have the crawler change direction More...
 
virtual void SetDirection (Directions newDirection)
 Use this method to set a new direction for the crawler More...
 

Public Attributes

bool CanMove = true
 whether or not this crawler can move. If false, it'll stay where it is. More...
 
Directions Direction = Directions.Clockwise
 the current direction this crawler is moving towards More...
 
float Speed = 10f
 the speed at which the crawler should move along the surface More...
 
float DistanceToSurface = 0.5f
 the distance from the surface at which the object should remain More...
 
LayerMask SurfaceLayerMask = LayerManager.ObstaclesLayerMask
 the layers the object will consider as a crawlable surface More...
 
Transform Model
 the visual representation of our crawler, usually nested under the top level containing the logic (the Crawler component) More...
 
bool RotateModel = true
 whether or not to rotate the crawler's model to match its movement direction More...
 
float RotationSpeed = 10f
 if RotateModel is true, the speed at which the model should rotate to match its movement direction More...
 
bool FlipModelOnDirectionChange = true
 whether or not the model should flip its x scale as it changes direction More...
 
Vector2 ForwardRaycastOffset = Vector2.zero
 the offset (from the crawler's position) from which we'll cast our forward ray More...
 
float ForwardRaycastLength = 2f
 the length of the forward raycast. This raycast detects upcoming walls, so you'll want to make sure it's of appropriate length. Don't hesitate to enable debug gizmos and check if it behaves as you expect More...
 
Vector2 DownwardRaycastOffset = Vector2.zero
 the offset (from the crawler's position) from which we'll cast our downward ray More...
 
float DownwardRaycastLength = 2f
 the length of the downward raycast. This raycast detects the surface below the crawler, so you'll want to make sure it's of appropriate length. Don't hesitate to enable debug gizmos and check if it behaves as you expect More...
 
float RaycastRotationAngleInterval = 10f
 when the crawler doesn't find a ground under itself, it'll start rotating on itself (in the movement's direction) until it finds a surface. This defines the increment at which it does that. The smaller the value, the more it will have to rotate to find ground. This should be tweaked based on the amount of different corner angles this crawler has to handle. If you only have right angles, then a value like 45 should be fine, for example. More...
 
int MaxAmountOfRotations = 5
 the maximum amount of rotations the object will perform on itself after reaching an edge to try and find new ground. You'll want to tweak it based on your level's geometry, angle interval and max distance to a potential wall behind on the path More...
 
float MaxDistanceInterval = 0.5f
 the maximum distance interval between two movements. This should be adjusted based on the size of the crawler and the terrain it needs to navigate. That's the distance at which the crawler will reevaluate its path. More...
 
bool DrawGizmos = true
 whether or not to draw gizmos in scene view to show the various raycasts More...
 
bool ChangeDirectionButton
 

Protected Member Functions

virtual void Awake ()
 On awake we initialize our crawler More...
 
virtual void Initialization ()
 On init we create a rotation reference we'll keep around as a reference of our current normal More...
 
virtual void FixedUpdate ()
 On fixed update we crawl and rotate our model More...
 
virtual void PerformCrawl ()
 Moves along the surface at the specified speed More...
 
virtual void HandleModelOrientation ()
 Changes the scale of the model to match its current direction More...
 
virtual void HandleModelRotation ()
 Rotates the model to tend towards the reference rotation at the specified speed More...
 
virtual void DetermineDirection ()
 Casts a number of rays to determine what direction the object should take next More...
 
virtual Vector2 ComputeOffset (Transform t, Vector2 offset)
 Computes the offset based on the current direction and rotation of our crawler More...
 
virtual void RegisterHit (RaycastHit2D hit, Vector2 offset)
 When we register a hit, we move at the specified distance and offset, and rotate our reference accordingly. More...
 

Protected Attributes

Vector2 _previousNormal
 
Vector2 _raycastOrigin
 
Vector2 _movementDirection
 
Vector3 _translation
 
Vector2 _forwardRaycastDirection
 
float _movedDistance
 
float _targetDistance = 0f
 
Transform _rotationReference
 
Vector2 _initialModelScale
 
Vector2 _modelScale
 
Quaternion _initialRotation
 

Member Enumeration Documentation

◆ Directions

the potential directions this object can move towards

Enumerator
Clockwise 
CounterClockwise 

Member Function Documentation

◆ Awake()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.Awake ( )
protectedvirtual

On awake we initialize our crawler

◆ ChangeDirection()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.ChangeDirection ( )
virtual

Call this method to have the crawler change direction

◆ ComputeOffset()

virtual Vector2 MoreMountains.CorgiEngine.SurfaceCrawler.ComputeOffset ( Transform  t,
Vector2  offset 
)
protectedvirtual

Computes the offset based on the current direction and rotation of our crawler

Parameters
t
offset
Returns

◆ DetermineDirection()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.DetermineDirection ( )
protectedvirtual

Casts a number of rays to determine what direction the object should take next

◆ FixedUpdate()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.FixedUpdate ( )
protectedvirtual

On fixed update we crawl and rotate our model

◆ HandleModelOrientation()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.HandleModelOrientation ( )
protectedvirtual

Changes the scale of the model to match its current direction

◆ HandleModelRotation()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.HandleModelRotation ( )
protectedvirtual

Rotates the model to tend towards the reference rotation at the specified speed

◆ Initialization()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.Initialization ( )
protectedvirtual

On init we create a rotation reference we'll keep around as a reference of our current normal

◆ PerformCrawl()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.PerformCrawl ( )
protectedvirtual

Moves along the surface at the specified speed

◆ RegisterHit()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.RegisterHit ( RaycastHit2D  hit,
Vector2  offset 
)
protectedvirtual

When we register a hit, we move at the specified distance and offset, and rotate our reference accordingly.

Parameters
hit
offset

◆ SetDirection()

virtual void MoreMountains.CorgiEngine.SurfaceCrawler.SetDirection ( Directions  newDirection)
virtual

Use this method to set a new direction for the crawler

Parameters
newDirection

Member Data Documentation

◆ _forwardRaycastDirection

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler._forwardRaycastDirection
protected

◆ _initialModelScale

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler._initialModelScale
protected

◆ _initialRotation

Quaternion MoreMountains.CorgiEngine.SurfaceCrawler._initialRotation
protected

◆ _modelScale

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler._modelScale
protected

◆ _movedDistance

float MoreMountains.CorgiEngine.SurfaceCrawler._movedDistance
protected

◆ _movementDirection

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler._movementDirection
protected

◆ _previousNormal

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler._previousNormal
protected

◆ _raycastOrigin

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler._raycastOrigin
protected

◆ _rotationReference

Transform MoreMountains.CorgiEngine.SurfaceCrawler._rotationReference
protected

◆ _targetDistance

float MoreMountains.CorgiEngine.SurfaceCrawler._targetDistance = 0f
protected

◆ _translation

Vector3 MoreMountains.CorgiEngine.SurfaceCrawler._translation
protected

◆ CanMove

bool MoreMountains.CorgiEngine.SurfaceCrawler.CanMove = true

whether or not this crawler can move. If false, it'll stay where it is.

◆ ChangeDirectionButton

bool MoreMountains.CorgiEngine.SurfaceCrawler.ChangeDirectionButton

◆ Direction

Directions MoreMountains.CorgiEngine.SurfaceCrawler.Direction = Directions.Clockwise

the current direction this crawler is moving towards

◆ DistanceToSurface

float MoreMountains.CorgiEngine.SurfaceCrawler.DistanceToSurface = 0.5f

the distance from the surface at which the object should remain

◆ DownwardRaycastLength

float MoreMountains.CorgiEngine.SurfaceCrawler.DownwardRaycastLength = 2f

the length of the downward raycast. This raycast detects the surface below the crawler, so you'll want to make sure it's of appropriate length. Don't hesitate to enable debug gizmos and check if it behaves as you expect

◆ DownwardRaycastOffset

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler.DownwardRaycastOffset = Vector2.zero

the offset (from the crawler's position) from which we'll cast our downward ray

◆ DrawGizmos

bool MoreMountains.CorgiEngine.SurfaceCrawler.DrawGizmos = true

whether or not to draw gizmos in scene view to show the various raycasts

◆ FlipModelOnDirectionChange

bool MoreMountains.CorgiEngine.SurfaceCrawler.FlipModelOnDirectionChange = true

whether or not the model should flip its x scale as it changes direction

◆ ForwardRaycastLength

float MoreMountains.CorgiEngine.SurfaceCrawler.ForwardRaycastLength = 2f

the length of the forward raycast. This raycast detects upcoming walls, so you'll want to make sure it's of appropriate length. Don't hesitate to enable debug gizmos and check if it behaves as you expect

◆ ForwardRaycastOffset

Vector2 MoreMountains.CorgiEngine.SurfaceCrawler.ForwardRaycastOffset = Vector2.zero

the offset (from the crawler's position) from which we'll cast our forward ray

◆ MaxAmountOfRotations

int MoreMountains.CorgiEngine.SurfaceCrawler.MaxAmountOfRotations = 5

the maximum amount of rotations the object will perform on itself after reaching an edge to try and find new ground. You'll want to tweak it based on your level's geometry, angle interval and max distance to a potential wall behind on the path

◆ MaxDistanceInterval

float MoreMountains.CorgiEngine.SurfaceCrawler.MaxDistanceInterval = 0.5f

the maximum distance interval between two movements. This should be adjusted based on the size of the crawler and the terrain it needs to navigate. That's the distance at which the crawler will reevaluate its path.

◆ Model

Transform MoreMountains.CorgiEngine.SurfaceCrawler.Model

the visual representation of our crawler, usually nested under the top level containing the logic (the Crawler component)

◆ RaycastRotationAngleInterval

float MoreMountains.CorgiEngine.SurfaceCrawler.RaycastRotationAngleInterval = 10f

when the crawler doesn't find a ground under itself, it'll start rotating on itself (in the movement's direction) until it finds a surface. This defines the increment at which it does that. The smaller the value, the more it will have to rotate to find ground. This should be tweaked based on the amount of different corner angles this crawler has to handle. If you only have right angles, then a value like 45 should be fine, for example.

◆ RotateModel

bool MoreMountains.CorgiEngine.SurfaceCrawler.RotateModel = true

whether or not to rotate the crawler's model to match its movement direction

◆ RotationSpeed

float MoreMountains.CorgiEngine.SurfaceCrawler.RotationSpeed = 10f

if RotateModel is true, the speed at which the model should rotate to match its movement direction

◆ Speed

float MoreMountains.CorgiEngine.SurfaceCrawler.Speed = 10f

the speed at which the crawler should move along the surface

◆ SurfaceLayerMask

LayerMask MoreMountains.CorgiEngine.SurfaceCrawler.SurfaceLayerMask = LayerManager.ObstaclesLayerMask

the layers the object will consider as a crawlable surface


The documentation for this class was generated from the following file: