Jump to content

How to force Kerbals to stand instead of float?


Recommended Posts

Hi everybody!

I'm trying to add a kind of magnetic boots to EVA'd Kerbals so that they can walk on the surface of space stations.

I thought I'll only have to apply a force pressing the Kerbal down to a part and it'll switch from 'float mode' to 'walk mode'. Unfortunately it doesn't work like that.

Is there a way to force a Kerbal to switch to 'walk mode'?

Link to comment
Share on other sites

This would be a really cool mod--but I can't help with the technical question, alas. I suspect that the game checks to see if you're on the surface of a world, and toggles animations based on that.

Link to comment
Share on other sites

  • 5 weeks later...
This would be a really cool mod--but I can't help with the technical question, alas. I suspect that the game checks to see if you're on the surface of a world, and toggles animations based on that.

Well, you can stand on a craft when it's airborne, even on low-gravity moons, so I suspect there's more to it than that. If you just apply a force anti-normal to your target surface (much like the gravity on a celestial body would do), there is little chance that a Kerbal will stand, most probably, it will just face-plant flat. ;)

It may very well be possible that a Kerbal's feet have a different collider which the game checks to see if it is "standing" on something. Basically, when the underside of a Kerbal's feet are flush with the collider of the part that it's supposed to stand on, it would be standing instead of floating/crawling.

Try forcing the rotation of your EVA Kerbal to always be normal to the part you're sticking it to, and see if that has any effects.

Link to comment
Share on other sites

Good idea but rotation isn't the problem. On Kerbin a Kerbal would always stand up, even if he hit the surface head first.

Maybe the game checks if he hit a PQS collider (I bet there's something like that) or if he's in an atmosphere.

Link to comment
Share on other sites

Maybe the game checks if he hit a PQS collider (I bet there's something like that) or if he's in an atmosphere.

Kerbals can stand on the Mun or on Minmus, even if they're on top of a flying craft.

Never tested that on *orbit* though. I do know that when transitioning from "Flying High" to sub-orbital or orbit, a Kerbal on EVA will instantly align itself tangential (face down) with the planet it's orbiting, while on a "Flying High" situation, it will align feet down.

If you can find the criterium for that you may be able to override it and trick the EVA Kerbal into thinking it's moving over a (local) surface.

Is it even possible to stand on asteroids?

Link to comment
Share on other sites

There is a collider in each foot (I've verified this myself):

http://forum.kerbalspaceprogram.com/threads/113748-Reference-Kerbal-EVA-model-transform-tree

Also, have a look at KerbalEVA.minWalkingGee and KerbalEVA.minRunningGee, which is set to .17 and .6 respectively by default. Maybe you could play with those when the boots are active?

Edited by lo-fi
Link to comment
Share on other sites

It may be something to do with gravity, not just force. I'll need to go back a few years, but I remember Scott Manley doing an experiment with the interior of a circular, hollow, space station where he created artificial gravity by spinning the station and was able to drive a rover under that gravity. Now, granted, gravity is simply force directed in a specific direction relative to the body in question, but I have a feeling it needs to be force that can be measured by one of those gravity measuring devices. So, if the force is being applied to the kerbal, but is not measurable by one of those gravioli thingies, then the kerbal is just being pressed up against something. If, however, the gravioli detects a gravitational pull then the kerbal might try to stand on the surface that is "below" them.

EDIT: or just read lo-fi's post. I spent too long thinking about what I wanted to say.

Link to comment
Share on other sites

I already tried that, too. ;) But no success.

Somewhere in the game is a piece of code which decides on certain conditions if a Kerbal should float or walk. I neighter found that code nor the conditions. I also didn't find a way to know what mode currently is active.

@Stoney3K

This sounds promising! I'll investigate that.

Link to comment
Share on other sites

I've got this. It looks like it's governed by the colliders in the Kerbals (feet?) - minRun and minWalk are probably minimum force with which the (maybe feet) colliders in the Kerbal touch whatever.

In this video, I'm holding the S key the whole time:

Gravity is NOT hacked. I've got a raycast running, which gives me some info to construct a vector to add a force to the Kerbal. When the Kerbal touches the ground with enough force, walking is enabled.

Also, it's hilarious:

- - - Updated - - -

Update: I noticed also that some game objects are disabled in certain states. The foot bone, for example, is disabled unless in ragdoll state. Interesting, huh? I couldn't sleep, and had a few minutes to mess about. I know floating was the opposite of what you wanted to do, but it turned out to be useful. I think.

Hacky, thrown together code if you want it, of course!

Link to comment
Share on other sites

Sure! Show me your code! :)

Walk mode really doesn't depend on a force which pushes Kerbals down. I let a 1 g force act on a Kerbal which pushed him into a space station. He just stuck to a part not switching to walk mode. Meanwhile the station began to spin faster and faster because of that force.

I didn't have time to investigate Stoney3K's observation yet. But I believe that could point me to the solution.

Link to comment
Share on other sites

Sure! Show me your code! :)

Walk mode really doesn't depend on a force which pushes Kerbals down. I let a 1 g force act on a Kerbal which pushed him into a space station. He just stuck to a part not switching to walk mode. Meanwhile the station began to spin faster and faster because of that force.

Aha, your method is correct, but that means you're fighting Newton's third law here.

You're pushing the Kerbal down towards the station, but there's nothing to stop the station from moving in an equal and opposite direction (away from your Kerbal) with the same acceleration. Your poor Kerbal is essentially "falling" towards the station which is just as rapidly running away from a Kerbal trying to kick it in the skin. ;)

Meaning, the acceleration witnessed by the Kerbal's feet is nearly zero. (Not coincidentally, that is also the reason why there is "weightlessness" in space, even though the gravitational pull is almost 1g in LEO)

The trick here would not be pushing "down" harder on your Kerbal, it would be to restrict the station you want to walk on from moving. You will only be able to exert a "weight" force if there is an inanimate object to stand on.

Link to comment
Share on other sites

Yep, I know that I have to add an equal counter-force to the station at the collision point. ;)

The station (in fact only a full orange tank) began to spin slowly, the Kerbal experienced nearly 1 g for a limited time (ca. 10+ seconds, then the rotation becomes very noticeable). Still no switch to walk mode during that time. :(

Link to comment
Share on other sites

Yep, I know that I have to add an equal counter-force to the station at the collision point. ;)

The station (in fact only a full orange tank) began to spin slowly, the Kerbal experienced nearly 1 g for a limited time (ca. 10+ seconds, then the rotation becomes very noticeable). Still no switch to walk mode during that time. :(

If you add an equal counter-force the station should not spin at all.

Link to comment
Share on other sites

EDIT: Ignore me, that doesn't work in orbit! Weirdly, the Kerbal stops being able to walk the moment what it's standing on isn't in contact with the ground any more. Sorry I can't be of much more help, but it's been fun to mess around with!

And now the spoiler tags have gone haywire!

Edited by lo-fi
Link to comment
Share on other sites

EDIT: Ignore me, that doesn't work in orbit! Weirdly, the Kerbal stops being able to walk the moment what it's standing on isn't in contact with the ground any more. Sorry I can't be of much more help, but it's been fun to mess around with!

I found out the same thing: Kerbals can't stand on flying objects, not even if they're hovering mere inches over the surface. Poor Jeanette Kerman here was unable to stand on the cargo bay floor, she would just back-plant once the plane takes off.

DpFrdUr.jpg

Link to comment
Share on other sites

Kerbals inherit the Vessel class, so I'm wondering if the mechanism in that which deals with it being splashed, landed etc. is used to determine what the Kerbal will do. They also swim, don't they? It's clearly not to do with orbits. I found that having a Kerbal stood on top of a command pod, it would be in the floating pose, unable to walk until the very moment the command pod hit the ground, at which point it would walk again, no matter how tenuous the pods contact with the ground might have been. I can't think of any situation a Kerbal would want to be walking, unless classed as "landed", so there's some sense to that line if thinking. Maybe.

Link to comment
Share on other sites

Update: I tried manually setting vessel.landed for the Kerbal. This prevents you from using RCS, stops the kerbal from going into the free fall pose, and makes it assume the low gravity leaping posture when not stood on something. Merits further investigation!

Link to comment
Share on other sites

II suggest you look at the KerbalEVA.fsm field. You can force pretty much any KerbalEVA state you want there, including floating, rag doll mode, etc. I'll post a list of states later once I have access to my computer.

I do have some code that manipulates the fsm here: https://github.com/HappyFaceIndustries/KerbalAnimationSuite/blob/master/Source/KAS_AnimationClip.cs

Look at the KerbalEVA_Utility class.

Edited by MrHappyFace
Added information
Link to comment
Share on other sites

Update: I think I got something semi-workable:

I turn the boots off and let the kerbal float away towards the end, though I've forgotten to reset the landed state in the code after that, so zero-G EVA stuff is still disabled. As MrHappyFace points out, the more intelligent way is probably to mess with the FSM. Now this seems to be possible, do let me know if you'd like some magnetic boots made for the kerbals! Would be a rather fun thing to do :D


using System;using System.Collections.Generic;
using System.Collections;
using System.Reflection;
using System.Linq;
using System.Text;
using UnityEngine;


namespace KerbalGadgets
{
public class MagBoots : VesselModule
{
KerbalEVA _kerbal;


GameObject _rayObject;


GameObject _targetObject;



Rigidbody _TargetRB;





Vessel _vessel;


bool isReady;


bool bootToggle;


float magForce = .5f;


public string ravInfo;


public float rayDistance = 0.2f;


public int layerMask = 0;

public void Start()
{
_kerbal = this.GetComponent<KerbalEVA>();
_vessel = this.GetComponent<Vessel>();


if (_kerbal != null)
{
Debug.LogWarning("Kerbal in EVA....!");


_rayObject = new GameObject("rayObject");

_rayObject.transform.position = transform.Search("bn_spA01").position;
_rayObject.transform.rotation = transform.Search("bn_spA01").rotation;
_rayObject.transform.parent = _kerbal.gameObject.transform;


#if DEBUG


if (_rayObject != null)
{
Debug.LogWarning("Found left hand foot");
_rayObject.SetActive(true);
Extensions.DebugLine(_rayObject.transform);
}
#endif
isReady = true;


}
else
{
Debug.LogWarning("Not Kerbal in EVA");
return;
}
}


public void Update()
{
if (Input.GetKeyUp(KeyCode.P))
{
bootToggle = !bootToggle;
if (bootToggle)
print("MagBoots Active");
else
print("MagBoots Disabled");
}
//print("State" + _vessel.state + "landed " + _vessel.Landed + "splashed " + _vessel.Splashed);
}


public void FixedUpdate()
{
if (!isReady)
return;
if (bootToggle)
_vessel.Landed = true;
else
return;
_rayObject.SetActive(true);

RaycastHit hit;


if (RayCast(rayDistance, _rayObject, _rayObject.transform.right, out hit))
{
_targetObject = hit.collider.gameObject;
_TargetRB = hit.rigidbody;
print(hit.collider.name);
}
else
{
_targetObject = null;
print("target null");
}

//print(ravInfo);
if (_targetObject != null)
{
print("Applying forces");
Vector3 direction = _rayObject.transform.position - hit.point;
_kerbal.rigidbody.AddForceAtPosition(-direction.normalized * magForce, hit.point);
if (_TargetRB != null)
_TargetRB.AddForceAtPosition(direction.normalized * magForce, hit.point);
else
print("no rigidbody L");
}

}


bool RayCast(float rayLength, GameObject rayObject, Vector3 direction, out RaycastHit hit)
{
var ray = new Ray(rayObject.transform.position, direction);
int tempLayerMask = ~layerMask;
return Physics.Raycast(ray, out hit, rayLength, tempLayerMask);
}
}
}

Link to comment
Share on other sites

II suggest you look at the KerbalEVA.fsm field. You can force pretty much any KerbalEVA state you want there, including floating, rag doll mode, etc. I'll post a list of states later once I have access to my computer.

I do have some code that manipulates the fsm here: https://github.com/HappyFaceIndustries/KerbalAnimationSuite/blob/master/Source/KAS_AnimationClip.cs

This is interesting. How far did you get on that particular project? It seems to have been a while since you made any changes

Link to comment
Share on other sites

_rayObject.transform.position = transform.Search("bn_spA01").position;

_rayObject.transform.rotation = transform.Search("bn_spA01").rotation;

I wonder why there's a Search() method. Is it defined in a custom class extension?

I ask because VS's autocompletion doesn't list it here.

Edit:

Never mind. I found it in KerbalFoundries.

Edited by *Aqua*
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...