Sign in to follow this  
uralkemal

follow the line

Recommended Posts

Quote:
Original post by uralkemal
hi, i want an object to move on a drawn line. How can do it?
To give any sort of useful answer, we'll probably need quite a bit more info. Here are some questions:

1. What programming language, graphics API, and platform are you working with? (Not all of these are directly relevant, but it would still be useful to know.)

2. Is the line (segment) always straight? Or is it arbitrary (i.e. 'curvy')? Are there any other constraints?

3. Is this a 2-d problem?

4. How is the line drawn? With the mouse? Some sort of touchpad?

5. How is the line represented internally once it's drawn (this is really only relevant if the line can be 'curvy')?

6. How should the object move along the line? Should its orientation change to reflect the 'direction' of the line at the current position?

7. Is it important that the object move at a particular speed? At a constant speed?

And anything else you can think of that might be relevant.

Share this post


Link to post
Share on other sites
thanks for your answer. It's a simple 2d platform. And an object has a constant speed. And the center of the object will on the line. The line drawn with mouse so not a straight line.

Share this post


Link to post
Share on other sites
Well, the generalized version -
Given coordinate points of the line in an array line[n]:
1) At point line[0], rotate to face line[1], draw object
2) Translate to line[1], rotate to face line[2], draw object.
3) Repeat for all points n in line[].

Anything more specific would require information about which API you are using in which language.

Share this post


Link to post
Share on other sites
We still don't have enough information. Go through jyk's questions one at a time and give us the most complete answer you can. Ideally, we'd like to see some code or pseudocode describing how you read in and store the line.

Admiral

Share this post


Link to post
Share on other sites
thanks for your answers. Ezzaral's idea seems well and i will try it. It's not importent what language i use(not decided yet). I just want to learn some ideas. And i am waiting for any other ideas.
thx...

Share this post


Link to post
Share on other sites
Is it a straight line or a curve.... i assume a straight line....

by ezzaral's method u are limited to a line segment(moreover u need to know all the points on the line in advance)... if u wana go further,
i got some thing for u... hope it will work.

a straight line has an equation y = mx + c ( y - y coordinate, x - x coordinate, m - slope, c - y intercept)

when u have this, the next step is easy. take a point on the line put ur object there... now we are all set...

Next increment x by a single unit, put the incremented value of x int the line equation. Now as u have one unknown(y), u can easyly calculate y from the equation... Just move ur object to that new point, this new point is ur next point on the line. there u go ur object is moving.... repeat this as long as u want(untill the object reaches end of ur frame).

( u can move forward of backward on the line by incrementig or decrementing x)
( u can also increment y by a unit and calculate x from the equation)...

if ur line is a curve nothing changes but the equation... every thing else is the same...

hope this helped u...

[Edited by - sreek on May 17, 2007 3:22:55 AM]

Share this post


Link to post
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

Sign in to follow this