We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am new in processing, I want to create car simulation at intersection but i am confused to handle moving object to turn left/right with rotate function. I wrote simple code but it didn't run well. May be you can help me to solve the problem I really appreciate it. Thanks
float x, y = 50, w = 40, h = 30;
float angle1=0.0;
void setup() {
size(1000, 700);
rectMode(CENTER);
}//func
void draw() {
background(0);
fill(255);
//display
translate(x, y);
rotate(angle1);
println("frameCount=" +frameCount +" angle="+angle1 + " x="+x + " y=" +y);
fill(200, 0, 0);//red
rect(0, 0, w, h);
//move
if (frameCount<300) {
x++;
//y++;
//angle1 += 0.01;
} else if (frameCount<=460) {
x+=1;
y++;
angle1 += 0.01;
} else if(frameCount<900){
w = 30;
h = 40;
x = 460;
y++;
angle1 = 0.0;
}
}
Answers
Thanks for your answer, it helped me a lot :)>-
Hi @TfGuy44 I'm sorry to bother you again. I still do not understand how the object can move to the left .. I tried many times but it always does not work ..Thank a lot
In this situations the best thing to do is to provided an MCVE demonstrating your problem.
Kf
When you set dx to negative it moves left
Because you add dx to px
But show your entire code
Actually I am a bit confused to do the rotation .. How to rotate 90 degrees but to the left.
here is another approach
it holds an event table that tells after how many milliseconds the car has to turn or drive etc.
thank you very much for all your help
you're welcome!
The turn left option doesn't work in all situations (only when the car is going south) - look at "init_turnRight" in switch to see how it's done.