This site requires JavaScript, please enable it in your browser!
Greenfoot back
Telatsu
Telatsu wrote ...

2013/12/13

Actor Following An Elliptical Line - Assistance Needed

Telatsu Telatsu

2013/12/13

#
I'm currently working on creating an application that showcases a car moving around a track. I'm having two issues: 1.) I'm having a lot of trouble getting the object to latch and move along the line so much so that I've scrapped my code a few times. I'm trying to adapt Danpost's previous code at: (http://www.greenfoot.org/scenarios/5340) but am having trouble understanding and thus adapting it. It seems a bit too complex for what I'm trying to do. 2.) My second issue is that since this is an object that is a car, it has a front and a back end, I need to make it look like the car is following the line around. So that means the object must be turning around as it follows the line forward. Any help would be greatly appreciated. I've been stuck for quite some time. As mentioned, here is the image I'm working with: I'm attempting to get it to follow the yellow line within the black track.
danpost danpost

2013/12/13

#
I feel that the difficulty in setting the proper rotation of the car can be circumvented by doing the following. At crucial points (at the beginning and ending of each curve) place an invisible actor that will convey to the car the instructions on how to proceed from that point. Since there are only two types of movement, straight forward and arcing, a boolean can be used to indicate the type of movement. For straight forward, you just need two ints; one for the speed in the x direction and one for the speed in the y direction, one of which will be zero. For arcing, you will also need only two, the x and y offsets to the focal point of the arc. From them, you can determine and save the focal point, the radius of the arc. You will need instance fields in the Car class to hold the necessary information in how to continue as the instructions are encountered.
Telatsu Telatsu

2013/12/13

#
How would you code getting the car to snap onto the line and follow it around, not including the rotation of the car, but simply acting as an object that would follow the yellow line as shown above? @danpost
danpost danpost

2013/12/13

#
I was able to create a scenario where the car would follow the line with the proper rotation all the way around the track. The movement of the car was done as follows: (1) while rotation is not a multiple of 90, turn clockwise (2) turn left 90 degrees and move forward one (3) while the color of the background is not yellow, turn right 90 degrees and move forward one (4) determine the new rotation of car by its location I will add another world and car to the scenario to use the method I first gave above and a button to go back and forth between the worlds; then, if you wish, I could upload the test demo.
You need to login to post a reply.