Headbob script not working right

Discuss coding questions, pull requests, and implementation details.
User avatar
Interkarma
Posts: 5188
Joined: Sun Mar 22, 2015 1:51 am

Re: Headbob script not working right

Post by Interkarma » Tue Mar 27, 2018 6:55 am

Well done. :)

You'll find the headbob toggle button at line 88 of DaggerfallPauseOptionsWindow. Just need to remove the BackgroundColor and wire up some functionality to it. Use another small Panel with a solid BackgroundColor to fill in the little square to show when option enabled/disabled.

For the setting itself, this should be added to SettingsManager with the default state in defaults.ini file. Follow the other settings for examples on how to set this up.

For observing the setting itself in your headbob script, the easiest way is just to do no work in Update() when headbob option is disabled. This will allow user to toggle on/off as needed.

Just post again if any problems. Either myself or someone else should be able to help.

User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Headbob script not working right

Post by MeteoricDragon » Wed Mar 28, 2018 3:27 am

I am having problems getting a red panel to appear on the head bobbing hole.

The event I made executes when the head bobbing panel is clicked. but the code below doesn't create a red panel. I was looking for other examples of how to do this but didn't see any.

panel headBobbingTick = new panel();

// other code

private void HeadBobbingButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
{
Debug.Log("Head Bobbing clicked, position: x: " + position.x + ", y: " + position.y);

headBobbingTick = DaggerfallUI.AddPanel(new Rect(1, 1, 4, 4));
headBobbingTick.BackgroundColor = Color.red;
}

User avatar
Interkarma
Posts: 5188
Joined: Sun Mar 22, 2015 1:51 am

Re: Headbob script not working right

Post by Interkarma » Wed Mar 28, 2018 3:47 am

You don't want to add the Panel every time the user clicks the button. Just create the Panel once during Setup() and enable/disable it based on the toggle state.

There are plenty of examples for how to create a Panel and add it to a component collection. For a hint, literally every control derives from a Panel, even the Button object you're capturing the event for is just another Panel. You could, for example, add your headBobbingTick Panel into that Button's component collection. :)

User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Headbob script not working right

Post by MeteoricDragon » Wed Mar 28, 2018 3:49 am

While you were typing that reply I figured it out, sorry to waste your time on an answer. I made it appear in a sort of random place on the options menu, but your reply still helped.

Wow i spent a lot of time on that one.

private void HeadBobbingButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
{
Debug.Log("Head Bobbing clicked, position: x: " + position.x + ", y: " + position.y);

headBobbingTick = DaggerfallUI.AddPanel(new Rect(64, 3, 4, 4), optionsPanel);
headBobbingTick.BackgroundColor = Color.red;
}

Edit: I See what you're saying now

Edit2: Although there is no disable property, but I can change the color to clear

User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Headbob script not working right

Post by MeteoricDragon » Wed Mar 28, 2018 8:52 pm

Interkarma wrote:
Tue Mar 27, 2018 6:55 am

For the setting itself, this should be added to SettingsManager with the default state in defaults.ini file. Follow the other settings for examples on how to set this up.
The default state I'm guessing will be 'ON') should be stored in the defaults (default on since vanilla Daggerfall defaults to it.

Line 114 of SettingsManager seems to already have a setting for headbobbing.

I got it to work. It toggles correctly and disables when on, enables when off. But doesn't save when closing game yet, i'm working on that.

Hey, I got a question about your preference. In my headbobber class, there are several variables that control specifically how much the player bobs side-to-side and up-and-down for Crouch, walk, run, and horse (includes horse and cart modes)

Was wondering if You'd like If I include a headbobbing scalar setting for the daggerfall pre-launch settings page? If yes, under gameplay section?

User avatar
Interkarma
Posts: 5188
Joined: Sun Mar 22, 2015 1:51 am

Re: Headbob script not working right

Post by Interkarma » Wed Mar 28, 2018 10:19 pm

There is a disabled property - just set control.Enabled = false. :)

As there's already a HeadBobbing boolean in default.ini and SettingsManager, you don't need to do anything special. Just use the setting that's already there for you and it will be saved.

Code: Select all

// To set directly
DaggerfallUnity.Settings.HeadBobbing = toggleState;

// To toggle
DaggerfallUnity.Settings.HeadBobbing = !DaggerfallUnity.Settings.HeadBobbing;

// To check
if (DaggerfallUnity.Settings.HeadBobbing)
{
    // Do true stuff
}
else
{
    // Do false stuff
}
MeteoricDragon wrote:
Wed Mar 28, 2018 8:52 pm
Hey, I got a question about your preference. In my headbobber class, there are several variables that control specifically how much the player bobs side-to-side and up-and-down for Crouch, walk, run, and horse (includes horse and cart modes)

Was wondering if You'd like If I include a headbobbing scalar setting for the daggerfall pre-launch settings page? If yes, under gameplay section?
Yep, that will be fine. Just wire up the default settings to "defaults.ini", the settings management to "SettingsManager", and then you can add the visual elements to the gameplay pre-launch page.

Great work so far. :)

User avatar
MeteoricDragon
Posts: 141
Joined: Mon Feb 12, 2018 8:23 pm

Re: Headbob script not working right

Post by MeteoricDragon » Thu Mar 29, 2018 2:45 am

Is there a way to get the velocity of the player, Not regular walking speed, but velocity even when the player starts to walk and stops walking?

User avatar
Interkarma
Posts: 5188
Joined: Sun Mar 22, 2015 1:51 am

Re: Headbob script not working right

Post by Interkarma » Thu Mar 29, 2018 3:32 am

The player's movement vector for any given frame is in moveDirection. If you want this, just make a read-only MoveDirection getter property in PlayerMotor. You shouldn't need to make any other changes in PlayerMotor.

The moveDirection is applied to the controller like so, and results in the actual movement impulse for that slice of time.

Code: Select all

collisionFlags = controller.Move(moveDirection * Time.deltaTime);
When reading MoveDirection property, don't forget to * Time.deltaTime to make it frame-rate independent if you need to.

Post Reply