Jump to content
Search Community

Tweening AROUND an object...

Dinkyfish test
Moderator Tag

Recommended Posts

Hello everyone, I've got the feeling that doing something like this will be a bit beyond my humble capabilities but I was wondering if it was possible to set and object so that it would tween from point A to point B going around another object? I'm working in AS3, using Flash CS4.

 

Basically I'm building a game with objects that can be controlled by the user. The objects are moved by clicking once on them to select them, then clicking somewhere else on the screen to send them there. There is, however, a 'blocked' area (circular in shape) in the centre of the screen that the object should not be able to enter. Ideally I'd like to be able to code my program so that if, for example, the user tries to send their object from the top left corner of the screen to the bottom right it will move there but travel around (not through) the blocked area. At the present moment in time I have it set so that if the object moves into the blocked area it will stop moving forwards and reverse a little until it is out of the area.

 

Is this possible? More importantly, will it be very difficult (I expect it will) as I'm running a little short on time! Cheers for any help you can provide :)

Link to comment
Share on other sites

Yeah, that's not exactly a simple thing. Certainly possible, though. Just takes math. And I'd recommend using the bezierThrough plugin to make it smoothly curve around the object. Basically, the concept would be to figure out the angle at which your object will travel between point a and b (as if it were going straight), add or subtract 90 degrees (depending on which edge it's closer to) and plot a point at that angle from the center of your "blocking" circle with the length being the radius of your circle (plus a bit more so that your object doesn't touch the edge). Then use that point as your bezierThrough point. Like I said - not super simple, but doable.

 

Good luck.

Link to comment
Share on other sites

Ah yes I can see how that would work, thank you! I think I'd also need to introduce some sort of check to see whether the object was going to pass through the blocked area at all or not... I'll have a good look into getting this up and running but with the amount of time I've got left I think it's going to have to be one of those 'would have been nice' ideas :D

 

Cheers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...