Movement of Objects in a simulation

后端 未结 4 1486
轮回少年
轮回少年 2021-01-26 03:45

i am currently making a flash \"pond\" with fishes in it, and i have the ability to add food pellets onto the pond, how should i make the movement of my fishes to the food x,y l

4条回答
  •  無奈伤痛
    2021-01-26 04:30

    This is a quick and easy way to do what you're after:

    public function moveToFood(food:Food):void
    {
        x -= (x - food.x) / 40;
        y -= (y - food.y) / 40;
    }
    

    For something a little nicer you'll probably need to look at your own small artificial intelligence for the fish (something like picking the nearest food, moving toward it at a constant pace and then starting to feed on it).

提交回复
热议问题