Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I get a 2d sprite to move to a position clicked on the screen, without bumping into other objects? I'm programming in java using the android API library

I have created a surface view and loaded my sprites as a bitmap object.

share|improve this question
1  
You might try doing an internet search on this topic before asking questions here. –  Jonathan Dickinson Dec 9 '11 at 7:46
    
@JonathanDickinson I think this is a valid question for gamedev. The question is about finding a way from A to B without bumping into other obstacles (if I understood correctly). –  bummzack Dec 9 '11 at 8:14
    
@bummzack in which case it's a duplicate. –  Jonathan Dickinson Dec 9 '11 at 8:19
    
@JonathanDickinson feel free to mark it as such then. –  bummzack Dec 9 '11 at 8:25

1 Answer 1

up vote 5 down vote accepted

It depends on your game. If you have a dense environment with restricted moving paths (eg. something like a maze), then you should look into path-finding. If you have only few and spaced obstacles which may even be moving, then look into steering-behaviors, especially obstacle-avoidance.

Update: While path-finding usually works with a starting location and a target-location (eg. your sprites current position and the position you clicked), this might not be so obvious with steering-behaviors. In the case of steering-behaviors, you can use a combination of behaviors. Eg. start with a behavior like "Arrival" where the target is where you last clicked. During this behavior, check for obstacles in the way and switch to the obstacle-avoidance behavior if you detect an obstacle in your path. As soon as the way is clear, re-apply the arrival behavior. Alternatively you could also implement your own behavior that takes everything into account.

share|improve this answer
    
Thanks for the information this definitely gives me much to think about and a bit of testing to do. –  kdavis8 Dec 10 '11 at 3:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.