@mdswamp said:
i used an area2d animation on my character for simulating the movement, (and i used get_collision_mask method for detecting collision, it shows collision), but it didn't work. what should i do for that part?
have you tried using the body_entered/area_entered signals? You can bind them to a function and then process from there. For example (untested. It should work with Godot 2):
func _ready():
get_node("path_to_area2D").connect("body_entered", self, "collision_with_body")
func collision_with_body(body):
print ("Collided with", body.get_name)
beside i use lerp for the ai because it moved with vibration, but now it moves like airplane, what method should i use for ai to move normal?
The problem is probably because of how you are using lerp. the third argument in lerp defines how far the returned value will be in regards to the inputted values. For example, here are some lerp calls and the returned values:
lerp(0, 10, 0.5) "returns 5"
lerp(100, 400, 0.2) "returns 160"lerp(0.1, 0.8, 0.75) "returns 0.625"
The reason this is important is because depending on how you have lerp setup, it can dramatically change. Look at the following for example:
var lerp_value = 0;
"Presume the code below will be called every _process call"
lerp(lerp_value, 10, 0.25);
" First call: lerp_value = 2.5 "
" Second call: lerp_value = 4.375 "
" Third call: lerp_value = 5.781 "
" Fourth call: lerp_value = 6.836"
" And so on"
As you can see, at first lerp_value is changing and getting a lot closer to the target, but as it gets closer and closer, it slows more and more. This is because of how we are using lerp_value as the minimum bound in lerp.
If we wanted the above example to work, we'd need to do something like this:
var lerp_percent = 0.0
var lerp_value = 0;
"Presume the code below will be called every _process call"
lerp_value = lerp(0, 10, lerp_percent);
lerp_percent += 0.25
" First call: lerp_value = 2.5 "
" Second call: lerp_value = 5.0 "
" Third call: lerp_value = 7.5 "
" Fourth call: lerp_value = 10.0 "
As you can see, just by changing which value we are editing, we can get vastly different results.
Based on what you have said, I would wager the problem you are having is similar to the first example, where as it gets closer and closer to the goal, it slows down more and more. The way to get around this is to store the position of the AI before it moves, and the end position of the AI. Then you can use something like this (untested. I think the code/functions used should work with Godot 2.0, but it's been awhile):
if (lerp_time <= 1):
global_position = lerp(starting_position, ending_position, lerp_time)
lerp_time += delta * MOVE_SPEED
if (lerp_time >= 1):
lerp_time = 1
" Then whenever you want to move, you do something like this: "
if (should_move == true):
starting_position = global_position;
end_position = global_position + movement;
lerp_time = 0;
even when i move mouse (which i haven't set mouse in input tab), ai begins to detect collision. but when i don't do anything, it seems detection goes to inactive mode. i changed my codes to use overlapping areas method and everything works but only if i move other player or hit something on keyboard or move mouse cursor. could someone help me with this problem? thanks
Strange. I would say it is either something in your code that is causing the issue, or it's a Godot 2 bug. It may be that you (or Godot 2) have a condition somewhere that is tied to there being active input. It's hard to say what could be causing the issue without looking at the project though.
I would suggest adding print statements and see if you can debug what is happening, or at least that is what I would do if I had the same problem. It is likely something is not being set correctly, or some leftover variable from another function is not being reset/changed, and that is causing the issue.
Hopefully this helps! It's been awhile since I've used Godot 2, so the code examples may need translating before they work (hopefully not though)