How to make complex physics movement

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Joubarbe
:warning: Old Version Published before Godot 3 was released.

Hi,

I’m new to Godot and game programming in general.

I know there are move() and move_to() functions for kinematic objects, but what I’d like to know is if it exists a function that take into account rotation, speed, acceleration?

For instance, if I have a ship (2D top-down view) pointing at (0,0), and if I want it to go to (0,180), where the mouse cursor clicked, what is the common way to make it rotate first, then manage to go to its destination? I mean, ships are big, it would need quite some place on the side to rotate. I thought a physics engine could do that easily, so I ask here if that’s the case with Godot.

Thanks.

:bust_in_silhouette: Reply From: eons

Using kinematic bodies (the one with direct movement, move) you need to program everything like on every other game engine.

Get your physics book and adapt all the small details by hand ^_^;


Here are some useful movement and rotation basics for Godot and the “look at” demo is good for rotations too:

http://codetuto.com/2016/01/godot-engine-movement-and-rotation-basics/


For limited rotation space:
Kinematics have a test_move function to prevent moving but not a test_rotation or even a collision-aware rotation method, you may need an extra Shape to apply manual overlap checks to prevent undesired movements.

Or just fake it: use areas and/or raycasts to check potential collisions before they happen.

Hmm, thanks for the answer… It’s weird though, I cannot find any example answering to my scenario; even if it’s in another language, it would be appreciated! There’s a lot of maths involved in these kind of move.

Joubarbe | 2016-11-25 20:30

Something simple (and visual) for detections, like a car’s parking sensor:


Just add the overlap/collision checks before rotation attempts.


For more advanced AI, you may want to look for steering behavior techniques, sounds complex at first but once you get your framework in shape your objects will move in a smart way.

In particular, arrival+collision avoidance (areas and raycasts can help to simplify the logic too).

https://gamedevelopment.tutsplus.com/series/understanding-steering-behaviors–gamedev-12732

eons | 2016-11-25 21:20

Very interesting read. I’ve implemented some of the basic features without too much difficulty (it’s just a start…). Thanks!

Joubarbe | 2016-11-26 16:09