Giter Club home page Giter Club logo

gdcustomraycastvehicle's Introduction

Custom Shape-cast based vehicle implementation for Godot 3.x

icon

A custom vehicle implementation emphasizing simplicity and adaptability.

Difference of this branch and master

This branch uses sphere casting instead of raycasting, which from my testing doesn't seem to have a large performance impact. The code has also been refactored somewhat as well.

The drive elements serve as a basis for any type of land vehicle that needs to be suspended by "springs" and propelled using driving force applied to the vehicle body against the a surface that provides traction (the ground).

This system primarily allows for the simulation of wheeled, tracked and hover vehicles with as many propulsion elements as needed.

In this project:

Currently, two different sample vehicles are provided:

  1. A tracked vehicle with 10 drive elements total (5 per track on each side) with a steering system that has neutral steer capability.

  2. A 4 wheel drive vehicle with 4 drive elements (1 per wheel) with traditional car steering.

The vehicle controllers for both vehicle is only a bare minimum. Realistic drivetrain, sound, animation and traction are not simulated but can definitely be added.

The default scene is the tracked vehicle. You can switch to the other vehicle by pressing escape to unlock the mouse and clicking on the 'Change to 4WD vehicle' button.

gdcustomraycastvehicle's People

Contributors

tobalation avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gdcustomraycastvehicle's Issues

Licence

Hi,

Thank you for sharing your work.
i am very interesting to use your work as a base for a very simple simulator in which i need tank track (and maybe try to create a rope/chain from this).
Can you please add a licence file to know what is allow?

Thank you again for you work,
TO

Input being handled more than once (4WD)

Input is being accumulated for each ray in rayElements.
4WheelRayVehicleController.gd

func handle4WheelDrive(delta) -> void:
	# 4WD with front wheel steering
	for ray in rayElements:
		# get throttle axis
		var throttle : float = Input.get_axis("ui_down", "ui_up")
		# get steering axis
		var steering : float = Input.get_axis("ui_left", "ui_right")
		
		# steer wheels gradualy based on steering input
		if steering != 0:
			currentSteerAngle -= steering * steerSpeed * delta
		else:
			# return wheels to center
			if !is_equal_approx(currentSteerAngle, 0.0):
				if currentSteerAngle > 0:
					currentSteerAngle -= wheelReturnSpeed * delta
				else:
					currentSteerAngle += wheelReturnSpeed * delta
		currentSteerAngle = clamp(currentSteerAngle, -steeringAngle, steeringAngle)
		frontRightWheel.rotation_degrees.y = currentSteerAngle
		frontLeftWheel.rotation_degrees.y = currentSteerAngle
		
		# apply drive force
		if throttle != 0:
			currentDrivePower = lerp(currentDrivePower, throttle * drivePerRay, delta * acceleration)
		else:
			currentDrivePower = lerp(currentDrivePower, 0.0 , delta * acceleration * 1.5)
		ray.applyDriveForce(global_transform.basis.z * currentDrivePower)

Currently, steerSpeed, wheelReturnSpeed, and acceleration are being adjusted once per wheel (4 times on the VBL). Removing it from the for loop and multiplying the affected variables by 4 should keep vehicle handling identical.
For Example:

export(float) var steerSpeed : float = 40.0
export(float) var wheelReturnSpeed : float = 120.0
export(float) var acceleration : float = 1.0
func handle4WheelDrive(delta) -> void:
	# 4WD with front wheel steering
	# get throttle axis
	var throttle : float = Input.get_axis("ui_down", "ui_up")
	# get steering axis
	var steering : float = Input.get_axis("ui_left", "ui_right")
	
	# steer wheels gradualy based on steering input
	if steering != 0:
		currentSteerAngle -= steering * steerSpeed * delta
	else:
		# return wheels to center
		if !is_equal_approx(currentSteerAngle, 0.0):
			if currentSteerAngle > 0:
				currentSteerAngle -= wheelReturnSpeed * delta
			else:
				currentSteerAngle += wheelReturnSpeed * delta
	currentSteerAngle = clamp(currentSteerAngle, -steeringAngle, steeringAngle)
	frontRightWheel.rotation_degrees.y = currentSteerAngle
	frontLeftWheel.rotation_degrees.y = currentSteerAngle
	
	# apply drive force
	if throttle != 0:
		currentDrivePower = lerp(currentDrivePower, throttle * drivePerRay, delta * acceleration)
	else:
		currentDrivePower = lerp(currentDrivePower, 0.0 , delta * acceleration * 1.5)
	for ray in rayElements:
		ray.applyDriveForce(global_transform.basis.z * currentDrivePower)

No real impact on performance, but looks cleaner.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.