Valheim

Valheim

5
   
Award
Favorite
Favorited
Unfavorite
Caption
"Diving was bad idea! Send SOS"
9 Comments
Wariat117  [author] Apr 9, 2021 @ 2:56pm 
Sadly...
formatting doesn't work on the screenshot comments so all spaces/tabulators are lost and code look like it's in sorry state...
Gladly programs generally automatically add them back, soo the code will look good after copy, paste, compile
Wariat117  [author] Apr 9, 2021 @ 2:52pm 
Some guy asked me for code "for diving" so I post it there in comment section.
It's just adding diving and nothing else, there is no balancing/whatever

You can stand on the ocean's floor and switch weapons there or regain stamina etc etc


Mobs can't dive, (code doesn't add it)
so either non-swimming one will wait for you at the ocean's floor
or swimming ones will wait at the water surface

Serpents wait at the surface.
During screenshot I lowered serpents a bit so they are underwater like me, but only cosmettically for screenshot, it's not in the code
Wariat117  [author] Apr 9, 2021 @ 2:50pm 
Code that remove camera lock, now you can look under water:

Class: public class GameCamera : MonoBehaviour
Method: private void GetCameraPosition(float dt, out Vector3 pos, out Quaternion rot)

Delete those lines of code from method (don't need to add anything):
float waterLevel = WaterVolume.GetWaterLevel(vector3, 1f);
if (vector3.y < waterLevel + this.m_minWaterDistance)
{
vector3.y = waterLevel + this.m_minWaterDistance;
this.m_waterClipping = true;
}
else
{
this.m_waterClipping = false;}
Wariat117  [author] Apr 9, 2021 @ 2:50pm 
Code that allows to dive up(crouch) and swim up(space):
Class: public class Character : MonoBehaviour, IDestructible, IWaterInteractable, Hoverable
Method: private void UpdateSwiming(float dt)

First remove this one line of code:
this.m_body.useGravity = true;
It's close to the bottom of method (under the code that you will be replacing)
Wariat117  [author] Apr 9, 2021 @ 2:50pm 
Replace this code:
float num2 = this.m_waterLevel - this.m_swimDepth;
if (base.transform.position.y < num2)
{
float t = Mathf.Clamp01((num2 - base.transform.position.y) / 2f);
float target = Mathf.Lerp(0f, 10f, t);
Vector3 velocity = this.m_body.velocity;
velocity.y = Mathf.MoveTowards(velocity.y, target, 50f * dt);
this.m_body.velocity = velocity;
}
else
{
float t2 = Mathf.Clamp01(-(num2 - base.transform.position.y) / 1f);
float num3 = Mathf.Lerp(0f, 10f, t2);
Vector3 velocity2 = this.m_body.velocity;
velocity2.y = Mathf.MoveTowards(velocity2.y, -num3, 30f * dt);
this.m_body.velocity = velocity2;}





With this:
if (this.IsPlayer())
{
if (ZInput.GetButton("Jump"))
{
Vector3 velocity = this.m_body.velocity;
velocity.y = 2f;
if (base.transform.position.y > this.m_waterLevel - this.m_swimDepth - 0.5f)
{
velocity.y = 0.5f;
}
this.m_body.velocity = velocity;
}
Wariat117  [author] Apr 9, 2021 @ 2:49pm 
else if (ZInput.GetButton("Crouch"))
{
Vector3 velocity2 = this.m_body.velocity;
velocity2.y = -2f;
this.m_body.velocity = velocity2;
}
else
{
Vector3 velocity3 = this.m_body.velocity;
velocity3.y = 0f;
this.m_body.velocity = velocity3;
}
this.m_body.useGravity = false;
}
else
{
float num2 = this.m_waterLevel - this.m_swimDepth;
if (base.transform.position.y < num2)
{
float t = Mathf.Clamp01((num2 - base.transform.position.y) / 2f);
float target2 = Mathf.Lerp(0f, 10f, t);
Vector3 velocity4 = this.m_body.velocity;
velocity4.y = Mathf.MoveTowards(velocity4.y, target2, 50f * dt);
this.m_body.velocity = velocity4;
}
else
{
float t2 = Mathf.Clamp01(-(num2 - base.transform.position.y) / 1f);
float num3 = Mathf.Lerp(0f, 10f, t2);
Vector3 velocity5 = this.m_body.velocity;
velocity5.y = Mathf.MoveTowards(velocity5.y, -num3, 30f * dt);
this.m_body.velocity = velocity5;
}
this.m_body.useGravity = true;}
Solitus Apr 9, 2021 @ 2:15pm 
well, at least this explains why they won't let you dive below the waters surface. I had suspected this is what would happen, thanks for confirming :)
Cake for Mumm-Ra Mar 25, 2021 @ 5:41pm 
You came to the wrong neighborhood MF xD
Wariat117  [author] Mar 22, 2021 @ 12:22pm 
The water is ultra transparent ;d
The weird "floating" thingies on the horizont is the water surface, to be precise, the waves