I want an "unit" that bounces at walls infinitely, and players must avoid it.
I have 2 options on how to develop this:
Move instantly: every 0.1 second move instantly to (current_pos_x + SIGN_X * SPEED_X, current_pos_y + SIGN_Y * SPEED_Y). There's regions around the area where the unit bounces, and they change SIGN_X and SIGN_Y. SPEED_X and SPEED_Y allow me to make it move faster or slower, as well as make it a bit random (SPEED_X could be SPEED_X+0.1 or -0.1 so the bounce is not 100% linear).
Unit orders: I haven't looked at this enough yet, but maybe the above could be made better with just telling the unit to patrol around, using SIGN variables to change the angle of the unit. My only problem here is that you must calculate the "go to" point for the unit.
Well, what way do you think is better? I wrote the first one in 5 mins, and works fine, though it looks a bit clumsy, using 0.1 at speed (the bigger the speed, the worse it looks). I want to get the best result possible. Maybe there's better ways to calculate collisions and bounce stuff around, but I didn't work on something similar to this before, just normal patrols.
The first option would be perfectly fine. Just don't forget to enable Blend. Also, move the unit every 0.0 seconds (which makes it one game loop, the shortest time gap you can do).
Also, you don't need any SIGN variable. Just use positive and negative real numbers for the X and Y velocity components.
Not sure what you mean, but I'd just use 2 custom values for each unit to represent their X and Y velocities.
And yeah Blend makes it so the actor is interpolated between the two points until the next game loop, so if you have a high fps you should notice the difference.
I want an "unit" that bounces at walls infinitely, and players must avoid it.
I have 2 options on how to develop this:
Well, what way do you think is better? I wrote the first one in 5 mins, and works fine, though it looks a bit clumsy, using 0.1 at speed (the bigger the speed, the worse it looks). I want to get the best result possible. Maybe there's better ways to calculate collisions and bounce stuff around, but I didn't work on something similar to this before, just normal patrols.
The first option would be perfectly fine. Just don't forget to enable Blend. Also, move the unit every 0.0 seconds (which makes it one game loop, the shortest time gap you can do).
Also, you don't need any SIGN variable. Just use positive and negative real numbers for the X and Y velocity components.
Ah, blend. I knew I was missing something (the option that makes insta move smoother, nope?). Also, thanks for tip on 0.0, didn't know.
As for velocity, I may use speed as a general variable for more than one unit, so that's why I use a sign for each unit :).
Not sure what you mean, but I'd just use 2 custom values for each unit to represent their X and Y velocities.
And yeah Blend makes it so the actor is interpolated between the two points until the next game loop, so if you have a high fps you should notice the difference.
What I have is regions around the area I want the unit to bounce on.
Then, the unit itself has instamove to (current_X_position+Speed_X*sign_X,current_Y_position+Speed_Y*sign_Y).
When the unit touches one of those regions, a trigger changes the signs. Signs themselves are just 1 and -1.
Speed variables may be a global thing, allowing me to change speed of all units.
I'm bad at explaining myself, lol.