Jump to content
  • Advertisement
Sign in to follow this  

Distance to obstacle in flash

This topic is 2785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I find the edge of an object in flash when I know the origin and a movement vector?
I am making a sideways scroller in flash and for the first time I am trying to create a tiny bit more advanced physics then usual.

Usually this would be the onTick event:

AdjustRectangleBasedOnKeysPressed(); // eg. If key.LEFT is pressed, decrease rectangle.x by a constant speed
if (WillNewRectangleFitInTheWorld())

This works fine for having a constant speed, but say that the speed is 4 pixels per frame, if the wall is 3 pixels away this will fail and the players will never be able to get closer to the wall, this looks really bad.

So I want to add another line to the function, and it's there im facing a design question.

I want to write:
GetDirectionVectorBasedOnKeysPressed(); //This will allow me to add gravity and other stuff

This is a better solution for more reasons, I can have a better boundingbox on the moving object.
The moving object can move closer to obstacles,

But the real issue here is getting the distance to the edge of an object based on a direction arrow, here is a small illustration:

(Black boxes are obstacles, red box is bounding box, grey arrow is the movement vector, green line is where the point I need to find)

I am fairly certain that this has been asked before, but Im not sure what to search for to get answers, so here goes.

Share this post

Link to post
Share on other sites
You might check out this [Edit: Formatting isn't working correctly on the forums right now, but that's a link] article. Also, search the forum archives for e.g. 'platformer collision detection' or 'platformer sat'.

Depending on your needs, you could also consider using an existing physics engine (I believe there's a Flash port of Box2D, for example).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!