What are the methods and properties of Body

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ondesic

When I get a “body_entered(body)” event I can check certain properties of the “body” variable like body.get_name() or body.queue_free()

Where do I find the other functions or properties of “body”?

Also, let’s say the object is an Alien scene that has a function called “eaten” in its script, how can I call it using the “body” variable?

:bust_in_silhouette: Reply From: Socrates

body is a PhysicsBody2d, e.g. a KinematicBody2dand has all these methods: http://docs.godotengine.org/en/latest/classes/class_physicsbody2d.html#class-physicsbody2d

If the Alien is some kind of PhysicsBody2d i think you can check if it has the function eaten() with`

if body.has_function(“eaten”):

and then call the function.

Also the autocomplete in the editor will give you a complete list of functions for anything, and the docs can be accessed in the editor with the “Search Help” button.

Socrates | 2018-03-23 05:50

I followed your link but there are no functions in the list of a PhysicsBody2D like has_function() . Autocomplete doesn’t give me a list of functions I can call on Body. In fact it doesn’t give me anything when I push “.”

Where can I find a list of all the functions like body.get_name() or body.queue_free() or body.has_function()?


As a side note,
if body.has_function("eaten") is true, how would I call the function “eaten”?
EDIT: for the side note I did figure out that you can just call body.eaten() and it will work

ondesic | 2018-03-23 15:04

Sorry it should be has_method() not has_function()

Also, in the docs has_method is a method of the Object class, which PhysicsBody2d inherits from. All the classes a class inherits from can be found at the top of the appropriate docs page, e.g. PhysicsBody2D inherits from CollisionObject2d, Node2D, CanvasItem, etc. and you have to click on those things to see all the methods available to PhysicsBody2D. Not sure why autocomplete wouldn’t be working though.

Socrates | 2018-03-23 19:06