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

2017/4/24

Racing Off-Track

DamonAG DamonAG

2017/4/24

#
I am looking for a simple example of a mud (slowdown) effect to implement into my short racing game. I have the track and the surrounding mud as separate objects, but I am having trouble figuring out what to use to slow the vehicle down. I am assuming I would place it inside the code of the vehicle as a while isTouching. I would like it to slow down while only in the mud, and go back to regular speed when not.
danpost danpost

2017/4/24

#
Make the speed of the vehicle variable. You may also want to use a smooth moving engine (track the vehicle's location in finer units than pixels). Then, while in mud, decrease the speed by some small percentage, otherwise increase by normal acceleration, capping the speed at it maximum value.
DamonAG DamonAG

2017/4/24

#
Do you have an example of this? I have a way that I thought would work, but it doesn't seem to be working. It only moves the car 1 and does not change to 2 on the track (the Bound is a png, so the track is not part of the image).
public void gas()
    {
        if (this.isTouching(Bound.class))
        {
            move(1);
        }
        else
        {
            move(2);
        }
    }
danpost danpost

2017/4/24

#
Okay, that is not a slow-down thing -- that is a half-speed thing (which is much more simple. That should work provided you are unconditionally calling that method from the act method of the class.
DamonAG DamonAG

2017/4/25

#
Alright, it seems to be working, but the collision boxes on either the car or the mud is larger than it appears to be. Is there a way to tweak the entity so that if the visible section of the car is touching the visible section of the mud, then the care would reduce to half speed? I can almost guarantee this is my problem, seeing as I have collision for checkpoints and the car, and the act is called before the car is visibly touching the checkpoint.
You need to login to post a reply.