VehicleWheel3D

    A 3D physics body for a VehicleBody3D that simulates the behavior of a wheel.

    VehicleWheel3D.swift:14
    class VehicleWheel3D

    A node used as a child of a VehicleBody3D parent to simulate the behavior of one of its wheels. This node also acts as a collider to detect if the wheel is touching a surface.

    Superclasses

    • class Node3D

      Most basic 3D game object, parent of all 3D-related nodes.

    Citizens in SwiftGodot

    Conformances

    • protocol CustomStringConvertible

      A type with a customized textual representation.

    • protocol Equatable

      A type that can be compared for value equality.

    • protocol Hashable

      A type that can be hashed into a Hasher to produce an integer hash value.

    • protocol Identifiable<ID>

      A class of types whose instances hold the value of an entity with stable identity.

    • protocol VariantRepresentable

      Types that conform to VariantRepresentable can be stored directly in Variant with no conversion. These include all of the Variant types from Godot (for example GString, Rect, Plane), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.

    • protocol VariantStorable

      Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.

    Type members

    Instance members

    • var brake: Double

      Slows down the wheel by applying a braking force. The wheel is only slowed down if it is in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the mass of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking.

    • var dampingCompression: Double

      The damping applied to the spring when the spring is being compressed. This value should be between 0.0 (no damping) and 1.0. A value of 0.0 means the car will keep bouncing as the spring keeps its energy. A good value for this is around 0.3 for a normal car, 0.5 for a race car.

    • var dampingRelaxation: Double

      The damping applied to the spring when relaxing. This value should be between 0.0 (no damping) and 1.0. This value should always be slightly higher than the dampingCompression property. For a dampingCompression value of 0.3, try a relaxation value of 0.5.

    • var engineForce: Double

      Accelerates the wheel by applying an engine force. The wheel is only sped up if it is in contact with a surface. The mass of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 50 range for acceleration.

    • var steering: Double

      The steering angle for the wheel, in radians. Setting this to a non-zero value will result in the vehicle turning when it’s moving.

    • var suspensionMaxForce: Double

      The maximum force the spring can resist. This value should be higher than a quarter of the mass of the VehicleBody3D or the spring will not carry the weight of the vehicle. Good results are often obtained by a value that is about 3× to 4× this number.

    • var suspensionStiffness: Double

      This value defines the stiffness of the suspension. Use a value lower than 50 for an off-road car, a value between 50 and 100 for a race car and try something around 200 for something like a Formula 1 car.

    • var suspensionTravel: Double

      This is the distance the suspension can travel. As Godot units are equivalent to meters, keep this setting relatively low. Try a value between 0.1 and 0.3 depending on the type of car.

    • var useAsSteering: Bool

      If true, this wheel will be turned when the car steers. This value is used in conjunction with steering and ignored if you are using the per-wheel steering value instead.

    • var useAsTraction: Bool

      If true, this wheel transfers engine force to the ground to propel the vehicle forward. This value is used in conjunction with engineForce and ignored if you are using the per-wheel engineForce value instead.

    • var wheelFrictionSlip: Double

      This determines how much grip this wheel has. It is combined with the friction setting of the surface the wheel is in contact with. 0.0 means no grip, 1.0 is normal grip. For a drift car setup, try setting the grip of the rear wheels slightly lower than the front wheels, or use a lower value to simulate tire wear.

    • var wheelRadius: Double

      The radius of the wheel in meters.

    • var wheelRestLength: Double

      This is the distance in meters the wheel is lowered from its origin point. Don’t set this to 0.0 and move the wheel into position, instead move the origin point of your wheel (the gizmo in Godot) to the position the wheel will take when bottoming out, then use the rest length to move the wheel down to the position it should be in when the car is in rest.

    • var wheelRollInfluence: Double

      This value affects the roll of your vehicle. If set to 1.0 for all wheels, your vehicle will be prone to rolling over, while a value of 0.0 will resist body roll.

    • func getContactBody() -> Node3D?

      Returns the contacting body node if valid in the tree, as Node3D. At the moment, GridMap is not supported so the node will be always of type PhysicsBody3D.

    • func getRpm() -> Double

      Returns the rotational speed of the wheel in revolutions per minute.

    • func getSkidinfo() -> Double

      Returns a value between 0.0 and 1.0 that indicates whether this wheel is skidding. 0.0 is skidding (the wheel has lost grip, e.g. icy terrain), 1.0 means not skidding (the wheel has full grip, e.g. dry asphalt road).

    • func isInContact() -> Bool

      Returns true if this wheel is in contact with a surface.