-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added auto move feature #2647
Added auto move feature #2647
Conversation
Can one of the admins please verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the code looks clean and I think you've got the right idea. Please have a look at the suggested changes.
private void startAutoMove(EntityRef entity) { | ||
isAutoMove = true; | ||
ClientComponent clientComponent = entity.getComponent(ClientComponent.class); | ||
new Thread(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho this should not be done with a new Thread, but with the help of DelayManager
. You can schedule events there, and cancel the periodic events if auto-move should stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an issue. I'll fix this bit! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skaldarnar I looked up DelayManager but I could not find any implementation of it. What should my action Id be? And where exactly am I supposed to define the action that has to happen periodically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zeokav I have some usage of DelayManager in one of my repos.
Check out Line 40 (get an instance), Line 78 (register delayed action) and Line 82F (handle the event). I think there are two different events for delayed and periodic action, so if you need the other one, you may want to inspect the source of delaymanager directly :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oniatus! Some small changes and I got it working. 👍
while(isAutoMove) { | ||
try { | ||
Vector3f viewDir = entity.getComponent(LocationComponent.class).getWorldDirection(); | ||
clientComponent.character.send(new CharacterImpulseEvent(viewDir.mul(8f))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CharacterImpulseEvent
likely makes the movement feel sluggish. The impulse will actually push the player forward, instigated by some external force, not actually the player moving by himself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skaldarnar : What can I use to make it feel smooth? I was looking for something that could simulate a key press event with the Forwards key pressed at all times but that drops inputs because of too many inputs from the entity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good question. Programmatic triggering of the movement key would be the best option imho. I have to look into that as well and will come back to you on this topic later 😉 For now, using the impulse event to get working in the first place is fine!
@skaldarnar I have made the change you asked for (Using delayed manager instead of making a new thread). :) |
@zeokav merged! What do you think about staying in automove mode when jumping? That way you could travel long distances in non-flat worlds as well. I still have to look into the key press event vs impulse event. |
@skaldarnar I was thinking of that too since the world is more multi-levelled than flat. Just have to change a line or two for that anyway. I'll club it along with my next PR. 😄 |
Contains
A PR to address #2557 . I have added a binding to enable auto run.
How to test
Open up a game and press R (default binding - can be changed from the inputs menu). Any other action will stop the auto run state.
Notes
More like questions before merging -