0 votes

So i'm trying to make a classic final fantasy style like game here but the difference is the movement of the character is not limited by grid (limited by grid : i.e. press ui_right and the char will move 16px to the right or something like that, mine is not limited).

Since i'm new to godot i don't really know how to do things in here
For every object has an Area2D and StaticBody2D for example:

Object TeddyBear
Object TeddyBear link to imgur

The Area2D is the active area of the teddy bear, the size are the same as the collision in StaticBody2D and collision in Area2D

Now what i want or how i want to do things may look like this:

var playerPos = Player.position
if(direction == "TOP"): playerPos += Vector2(0,-32)
elif(direction == "DOWN"): playerPos += Vector2(0,32)
elif(direction == "LEFT"): playerPos += Vector2(-32,0)
elif(direction == "RIGHT"): playerPos += Vector2(32,0)

//this is where i get stuck, i don't know the next code but, i want it more or less like this

if (playerPos is inside teddy.Area2D.collisionShape): canInteract = true

Am i doing things right or not? Please correct my way to do this if i am wrong or if this way is right then please help me on how to code that problem above

I am a new game developer and before using godot i was using unity, so changing to this newly released godot v3.0 stable needs me to get used to it

Thanks :)

in Engine by (21 points)

1 Answer

0 votes

Don't know if this may help you, but for my game Batty Bat, I had to do something similar for my enemies (Hornets). I wanted the hornets to follow Batty Bat (player) if Batty Bat got to close to them. So I looked at the players (bat) position and enemies (hornet) position and calculated the distance. If the enemy was within the specified distance then I started moving the enemy towards the player. If the player got outside the specified distance then I stopped the enemy from moving towards player. I counted the number of times the player got within the distance of enemy as well and if it reached a certain number of times then I made the enemy always follow the player. Ultimately if the player and the enemy overlap collision areas then the enemy is removed and the health of the player is subtracted.

The code is on the developers forum here: https://godotdevelopers.org/forum/discussion/18943/basic-2d-enemy-script-including-ai-follow-swarm

Hope this helps,
Gerry

by (204 points)

I appreciate your help but that is not what i'm looking for, i'm afraid
I checked your script
The swarm there will explode when the body (player) enter the swarms area
Not really what i'm looking for, but i appreciate it
So thank you so much :)

Ohh and one more thing

At least i learn how to make object follows my player
It will be really helpful for my future game development since there is a scene where the enemy search the player like your swarm did there

So once again, thanks :D

In mine, you are correct, " The enemy shrinks away" but it doesn't mean you can't do something else instead. What are you trying to do when the player interacts with the Teddy Bear?

just simply show a dialogue box
it really is a simple problem actually but i just dont know how to do this in godot
"to interact with the object in front of you"
thats what i wanna do
with this area2D i have, the player only need to enter the area2D of the TeddyBear object and this cause a problem where i can "interact with the teddy bear" even though my player direction is not directed to the teddy
so its kinda... stupid... what i want to do to fix this is to enable "canInteract" if the player's direction is directed to the object (teddy)
simple right? its actually a basic problem but i just dont get how can i do this in godot :/

Nevermind, i found the answer already
Turns out everything can be found in the godot documentation
Facing Part

Anyway thanks again for your support :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.