HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Determining vehicle jump landing quality

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
qualitydetermininglandingjumpvehicle

Problem

I am writing a game where a car drives and makes jumps. When a jump is landed, the player is rewarded if they land all four wheels either at the same time, or near to the same time. If they don't, they are penalised.

I am concerned my solution is not well abstracted (although I am open to all topics of feedback), and particularly that it will not be very extensible in the future should I come to add additional things to check for (such as bonuses for good air time, or tricks) on landing.

```
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

///
/// Checks if the car has made a good landing or not.
///
[RequireComponent(typeof(CollisionEvent))] //Unity engine code to ensure a CollisionEvent is always attached to the same object as this script.
public class GoodLandingChecker : MonoBehaviour
{

///
/// Gets or sets the bad landing threshold.
/// When a bad landing occurs, the player is penalised.
///
///
/// The bad landing threshold.
///
public float BadLandingThreshold
{
get { return badLandingThreshold; }
set { badLandingThreshold = value; }
}

///
/// Gets or sets the good landing threshold.
/// When a good landing occurs, the player is rewarded.
///
///
/// The good landing threshold.
///
public float GoodLandingThreshold
{
get { return goodLandingThreshold; }
set { goodLandingThreshold = value; }
}

///
/// Gets or sets the great landing threshold.
/// When a great landing occurs, the player is rewarded greatly.
///
///
/// The great landing threshold.
///
public float GreatLandingThreshold
{
get { return greatLandingThreshold; }
set { greatLandingThreshold = value; }
}

///
/// Gets or sets the minimum flying time before a landing will be considered.
///
///
/// The minimum flying time.
///
public float MinimumFlyingTime
{

Solution

First, I am not a C# programmer, but a Java programmer. So maybe some of what I write here is wrong for C#.

-
You write too many comments. Let the code speak for itself.

-
GoodLandingChecker_CollisionEntered Are you supposed to use underscore notation in C#?

-
You can probably find a better name for WheelLanded. Either OnWheelLanded if it's a callback, or something which is a verb otherwise, ie analyzeLanding.

-
I would split WheelLanded in a series of methods:

  • a method that returns the height difference



  • a method that transform the numerical height into an enum



  • one (or many) delegates that register to the get the enum result.



For example, the debugging print out and the added forward motion would be two separate delegates.

-
I am not sure if FlyingChecker should be separated from this class. Maybe you could have the method that determines what kind of landing (enum) it is in FlyingChecker, but have the delegates that act on that information being defined elsewhere.

Context

StackExchange Code Review Q#62846, answer score: 4

Revisions (0)

No revisions yet.