Skip to content

Player Gravity

SirAardvark edited this page Aug 30, 2021 · 2 revisions

Usage

Player gravity is added so when the user jumps they have something to bring them back to the ground.

The amount of gravity can be changed however it must also be changed in KeyboardPlayerInputComponent

If we want to change gravity during a game a GravityComponent will need to be made to update it for all functions.

Implementation

All code is in PlayerActions

The old way player movement was initiated:

OLD VARIABLE - private Vector2 walkDirection = Vector2.Zero.cpy();

The new way player movement is initiated. The player is added with -1f (1 m/s force downwards) instead of not moving on spawning.

The gravity variable is used to check the player is not moving. e.g. not moving up, down, left or right.

// Sets gravity to 1 m/s for comparing
private static final Vector2 gravity = new Vector2 (0, -1f);
// Sets player movement and adds gravity of 1 m/s
private Vector2 walkDirection = new Vector2 (0, -1f);

Anywhere that used the below has been replaced with (mostly in KeyboardPlayerInputComponent)

// OLD
variable = Vector2.Zero;
// NEW 
variable = gravity;

Table of Contents

Home

Introduction

Main Menu

Main Game Screen

Gameplay

Player Movement

Character Animations

Enemy Monster Design and Animations

Game basic functionalities

User Testing

GitHub Wiki Tutorial

Game Engine

Getting Started

Documentation

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally