Giter VIP home page Giter VIP logo

gd_playermovement's Introduction

gd_playermovement

Simple implementation of input controls for 3D object movement in godot.

The usual implementation of player movement in games is made in the "update" or "physics/process" functions which are called once per frame.

This makes sense for everything physics related, object movement included, however i wanted to find a way to keep these functions as clean and readable as possible.

Avoiding having to check for user input on every frame. Here is an approach that uses signals/events instead.

In the physics/process function we will be applying a costant force to the object in axis, X Y & Z.

The applied force will always be 0 in any direction:

apply_central_force(align_force * m_input * 1200.0 * delta)

The value of the applied force on each axis will be changed by the events/signals recieved from the user.

eg.

if event.is_action_pressed("move_left") || event.is_action_pressed("move_right"):
	m_input.x = Input.get_axis("move_left", "move_right")
if event.is_action_released("move_left") || event.is_action_released("move_right"):
	m_input.x = Input.get_axis("move_left", "move_right")

the get_axis() function will return a value of -1, 0 or 1 depending on the the event that took place, left or right, front or back, or 0 if none.

This script also includes an horizontal rotation function for a camera object '$TwistPivot'.

The force applied forward will always match with the direction the camera is facing:

view_pos = $TwistPivot align_force = view_pos.basis

gd_playermovement's People

Contributors

iurilandolt avatar

Watchers

 avatar

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.