Joseph,
The Whenevent has several parts:
WhenEvent[
x[t] == -4, {Print["t=", t, " x(0)=", x[t], " x'(0)=", x'[t]],
x'[t] -> 2*x'[t], x[t] -> -2,
Print["After bump: t=", t, " x(0)=", x[t], " x'(0)=", x'[t]]}];
the first part
x[t] == -4
is a condition so the event happens when the position hits -4. you can trigger on velocit (x'[t]) or anything else by changing this constraint. The next part is a list. The list contains a series of actions you are going to do when you hit the event (in this case when x[t] == -4.) First, I printed a message so I can see what is happening at the beginning of the event:
Print["t=", t, " x(0)=", x[t], " x'(0)=", x'[t]]
I get the time of the event and the x[t] and x'[t] values. The next thing I do is alter the states of the system (as I believe that you wanted to do). First I changed the position instantaneously and then I changed the velocity instantaneously.The changes make no physical sense but they showed what you can do:
x'[t] -> 2*x'[t]
instantaneously changes the velocity to be 2 times the current velocity at the when event (x[t]==-4). If you look at the graph you will see the velocity double at the instant the position hits -4. Next
x[t] -> -2
sets the position to jump from the current value of -4 to the new value of -2.
The last step prints out a message to show the new, updated values that I just changed. If you look at the plots, you can see the simulation pick up at the event with the new X and X' values. Obviously you can put in more meaningful changes to your states.
I hope this helps.
Regards,
Neil