Giter Site home page Giter Site logo

lutzgrosshennig / unity3d-advanced-grid-movement Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 4.0 58.56 MB

An more advanced approach for grid based movement in Unity3d games.

License: MIT License

C# 100.00%
unity unity3d dungeon crawler grid based movement gamedev game development

unity3d-advanced-grid-movement's Introduction

Advanced grid based movement for dungeon crawler type games.

An more advanced approach for Dungeon Master, Eye of the Beholder, Legend of Grimrock style grid based movement in Unity3d games.

In the past I wrote the https://github.com/LutzGrosshennig/unity3d-AnimatedGridMovement-Camera script which I used for my 'Xenomorph 2409' game project. back then.

Some fellow gridders pointed out that the movement of that script is way to linear and they are right about it. So I started to write this more advanced script that will give you a lot more control over the player movement.

Screenshots

Screenshot Screenshot

Whats new?

  • Fully editable animation curve for the movement and head bob
  • Command queueing. Plan your steps in advance!
  • Run/dash mode (experimental). Hold and press 'W' to advance even faster (with separate headbob/movement curves).
  • Height system. You can now climp stairs and slopes. This enables a new dimension (literally) for level design!
  • A basic event based footstep system and an generated example "footstep" sample you need to replace really soon ;-)
  • Full Unity3d project including a prebuild sample level and some crappy 3d collision detection code (just to showcase)
  • Oblique viewing frustum. A common problem of new 3d dungeon crawlers is, that you can't see enought of the tile you are currently standing on, this is caused by the default symetrical view frustrum on most 3d engines, switching to an asymetrical view frustrum adresses the issue. This is done by shifting the camera lens down in the physical camera emulation of Unity3d.

Materials used

Usage

There is a prebuild test level to walk around. Since this level is prebuild there is no 2d map to back it up but it gives you full control of your 3d world. Of course you can also generate the 3d level based on a 2d level map and then use the 2d map to apply your game logic, or you derive a 2d map based on what you build in 3d the choice is yours, both paths have there pro's and con's.

I'll update the documentation step by step but if you have a specific question, just open an issue and I'm happy to help.

Should be pretty self explainatory if you are not completly new to Unity3d. If you have questions create an issue and I will answer and update this readme. Otherwise you may want to check out the simpler version of the script (linked above).

Documentation is work in progress.

The scripts

You will find four scripts that do everything you need to get going.

AdvancedGridMovement.cs

This is the main script that handels the actuall movement and the animation of the movement. It also contains some very basic collision detection that I want to move out of the responsibilites of the script at some point in time. The collision detection code is very crude and I advice against the usage inside of production code as it uses tags to find gameobjects which can get rather slow pretty quickly in large scenes.

AdvancedOptions

InputHandler.cs

Since the sample still uses the old Input-System I wanted a way to separated the game logic from the pesky GetKeyXYZ calls required by the old system. Think of this as a simplified version of new Input-System where you are able to bind certain keys to an action. Its not really needed for the grid movement but makes it easy to separate game logic from the Input system. If you want to use the new Input-System in your project you dont need this.

InputHandlerOptions

MovementQueue.cs

This script handels queuing of commands and has a dependcy towards the AdvancedGridMovement.cs script to detect if the last movement command is completed before triggering a queued command. Therefore they need to exist on the same Gameobject.

MovementQueueOptions

FootstepSystem.cs

This is a simple system that can be used to add a footstep system to the player. Just assign two AudioSources for the left and right foot and assign some Audioclips that are played when the method Step() is called. The scipt handles left and right steps automatically so you just need to call Step() or Turn() to initiate the playback of the assigned AudioClips.

FootstepSystemOptions

Whats next?

The code could definiatly use some refactorings. There are some dependcies and responsiblities I'm not happy with. However "done!" is always better than "I will only release it when its perfect!". Of course I will use the scripts in "Xenomorph 2409" as well.

Challenge

You are not happy with the default animation curves and you found better ones? Great! Please share them with us!

Have fun with it!

Lutz

unity3d-advanced-grid-movement's People

Contributors

lutzgrosshennig avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

unity3d-advanced-grid-movement's Issues

The Unity3D project needs some restructuring.

Currently everything is on the toplevel directory which makes it unnessarily hard to integrate it into existing projects. It would be better if we use the more commonly used project structure an place the animated movement into an subfolder under a "Plugins" folder.

In addition it would not hurt to update the project to atleast Unity3d 2021 LTS.

Investigate "CompensateRoundingErrors()" method

The code of AdvancedGridMovement is based on the code from https://github.com/LutzGrosshennig/unity3d-AnimatedGridMovement-Camera where the target coordinates where interpolated and the CompensateRoundingErrors() method was required to circumvent an accumulation of IEEE floating point rounding errors.

Since the current implementation does not interpolate but instead evaluates the target position using an AnimationCurve a contributer of the "Dungeon Crawler Game Jam 2022" https://itch.io/jam/dcjam2022 raised the valid question if the code is still useful.

This needs to be investigated for the movement as well as for turning.

Replace static prebuild level with an 2d map to 3d level generator

Currently there is an static prebuilf 3d level but no 2d map that can be used for collision detection and AI.

So lets add this to the project.

Steps to do:

  • create 3d prefabs for room and corridor sections.
  • create a level generator that takes a 2d map and generates a 3d world based on the prefabs.
  • replace the 3d collision detection with a 2d one based on the 2d map.

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.