Jump to content

How to force Kerbals to stand instead of float?


Recommended Posts

Y'know, I was thinking a bit (I know, scary right?) while reading back a page or so (yes, I know that pretty much means every page, since there are only two other pages at the time of writing this) about the kerbal inheriting the vessel class and got to thinking that if this magnetic boots thing can be realized, we might then be able to make it into a magnetic-landing-gear mod to allow for artificial gravity on a space-based landing strip or something. In the end, this could factor into the development of a non-docking tie-down for cargo. Don't mind me, just dreaming here.

Also, I remembered another mod from back when asteroids were still parts that you could build a craft around and I remember that one of them was supposed to have some form of gravity field around it. I don't remember if that allowed kerbals to walk on it, and I don't think the mod is even available anymore, but it likely would have helped somewhere along the way.

Link to comment
Share on other sites

magnetic-landing-gear

You can already do that with KAS magnets. ;)

As for the magnetic boots the answers in this thread are a great help! I thank you all for that! :)

Now that I'm able to let the Kerbal switch to walk mode I'm experimenting a lot. One of the results: Kerbals do push themselves upwards during each step they take. That's interesting because that push is big enough to overcome any force pointing downwards. Atm in my code the magnets only activate when a collision takes place. And each step causes them to lose contact with the ground and the Kerbal floats away. ^^

Currently I'm implementing a detection of nearby parts and the magnetic attraction towards them. When finished I combine that to calculate a final force and direction where the Kerbal will be pushed towards. Could result in unexpected behavior when being near complicated part arrangements. :confused: ^^

Link to comment
Share on other sites

Ah, I know what's going on there. It's not to do with force: Certain GameObjects in the Kerbals get disabled in certain states; walking is one of them. You'll notice that I create a GO, set it to the position of "bn_spA01" then parent it so the top level transform of the Kerbal? This is deliberate. If you run the raycast from "bn_spA01", the raycast stops the moment the Kerbal starts walking. Don't be fooled; it's nothing to do with forces. Hope that helps!!

Link to comment
Share on other sites

Thanks for the warning! I'll check if the two transforms ("footCollider_l" & "footCollider_r") I query behave the same as "bn_spA01".

Edit:

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.

If someone want to know the states, here's a list:

Idle (Grounded)

Walk (Arcade)

Walk (FPS)

Turn to Heading

Run (Arcade)

Run (FPS)

Low G Bound (Grounded - Arcade)

Low G Bound (Grounded - FPS)

Low G Bound (floating)

Ragdoll

Recover

Jumping

Idle (Floating)

Landing

Swim (Idle)

Swim (fwd)

Ladder (Acquire)

Ladder (Idle)

Ladder (Lean)

Ladder (Climb)

Ladder (Descend)

Ladder (Pushoff)

Clamber (P1)

Clamber (P2)

Clamber (P3)

Flag-plant Terrain Acquire

Planting Flag

Seated (Command)

Grappled

I used this code to get 'em:

KerbalEVA eva = (KerbalEVA) this.part.Modules["KerbalEVA"];
System.Collections.Generic.List<KFSMState> stateList = (System.Collections.Generic.List<KFSMState>) eva.fsm.GetType().GetField("States", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(eva.fsm);
stateList.ForEach(state => Debug.Log(state.name));

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

As promised, here's my list of states. It also contains information about the events each state has.

each event can have a state it will transition to when it's called, which is denoted by the => after the name of the state (N/A if no transition), then a colon and the updateMode of the event.

For example, you could run the "Stumble" event to go to the Ragdoll state.


[LOG 18:48:23.213] State: Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.214] ----- Event: Move (Arcade): => Walk (Arcade) : FIXEDUPDATE
[LOG 18:48:23.214] ----- Event: Move (FPS): => Walk (FPS) : FIXEDUPDATE
[LOG 18:48:23.214] ----- Event: Move Low G (Arcade): => Low G Bound (Grounded - Arcade) : FIXEDUPDATE
[LOG 18:48:23.215] ----- Event: Move Low G (FPS): => Low G Bound (Grounded - FPS) : FIXEDUPDATE
[LOG 18:48:23.215] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.216] ----- Event: Fall: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.216] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.217] ----- Event: Pack Toggle: => N/A : UPDATE
[LOG 18:48:23.217] ----- Event: Feet Wet: => N/A : UPDATE
[LOG 18:48:23.217] ----- Event: Ladder Grab Start: => Ladder (Acquire) : UPDATE
[LOG 18:48:23.218] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.218] ----- Event: Boarding Part: => N/A : UPDATE
[LOG 18:48:23.219] ----- Event: Flag Plant Started: => Flag-plant Terrain Acquire : MANUAL_TRIGGER
[LOG 18:48:23.219] ----- Event: Seat Board: => Seated (Command) : MANUAL_TRIGGER
[LOG 18:48:23.220] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.220] State: Walk (Arcade) : FIXEDUPDATE
[LOG 18:48:23.221] ----- Event: Hdg Acquire Start: => Turn to Heading : UPDATE
[LOG 18:48:23.221] ----- Event: Move (FPS): => Walk (FPS) : FIXEDUPDATE
[LOG 18:48:23.221] ----- Event: Start Run: => N/A : FIXEDUPDATE
[LOG 18:48:23.222] ----- Event: Stop: => Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.222] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.223] ----- Event: Fall: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.223] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.224] ----- Event: Feet Wet: => N/A : UPDATE
[LOG 18:48:23.224] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.224] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.225] State: Walk (FPS) : FIXEDUPDATE
[LOG 18:48:23.225] ----- Event: Hdg Acquire Start: => Turn to Heading : UPDATE
[LOG 18:48:23.226] ----- Event: Move (Arcade): => Walk (Arcade) : FIXEDUPDATE
[LOG 18:48:23.226] ----- Event: Start Run: => N/A : FIXEDUPDATE
[LOG 18:48:23.227] ----- Event: Stop: => Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.227] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.227] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.228] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.228] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.229] State: Turn to Heading : FIXEDUPDATE
[LOG 18:48:23.229] ----- Event: Hdg Acquire Complete: => Idle (Grounded) : UPDATE
[LOG 18:48:23.230] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.230] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.231] State: Run (Arcade) : FIXEDUPDATE
[LOG 18:48:23.231] ----- Event: Hdg Acquire Start: => Turn to Heading : UPDATE
[LOG 18:48:23.231] ----- Event: Move (FPS): => Walk (FPS) : FIXEDUPDATE
[LOG 18:48:23.232] ----- Event: End Run: => N/A : FIXEDUPDATE
[LOG 18:48:23.232] ----- Event: Stop: => Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.233] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.233] ----- Event: Fall: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.233] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.234] ----- Event: Feet Wet: => N/A : UPDATE
[LOG 18:48:23.234] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.235] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.235] State: Run (FPS) : FIXEDUPDATE
[LOG 18:48:23.235] ----- Event: Hdg Acquire Start: => Turn to Heading : UPDATE
[LOG 18:48:23.236] ----- Event: End Run: => N/A : FIXEDUPDATE
[LOG 18:48:23.236] ----- Event: Stop: => Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.237] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.237] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.238] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.238] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.238] State: Low G Bound (Grounded - Arcade) : FIXEDUPDATE
[LOG 18:48:23.239] ----- Event: Hdg Acquire Start: => Turn to Heading : UPDATE
[LOG 18:48:23.239] ----- Event: Move Low G (FPS): => Low G Bound (Grounded - FPS) : FIXEDUPDATE
[LOG 18:48:23.240] ----- Event: Low G bound: => Low G Bound (floating) : UPDATE
[LOG 18:48:23.240] ----- Event: Stop: => Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.241] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.241] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.242] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.242] State: Low G Bound (Grounded - FPS) : FIXEDUPDATE
[LOG 18:48:23.242] ----- Event: Hdg Acquire Start: => Turn to Heading : UPDATE
[LOG 18:48:23.243] ----- Event: Move Low G (Arcade): => Low G Bound (Grounded - Arcade) : FIXEDUPDATE
[LOG 18:48:23.243] ----- Event: Low G bound: => Low G Bound (floating) : UPDATE
[LOG 18:48:23.244] ----- Event: Stop: => Idle (Grounded) : FIXEDUPDATE
[LOG 18:48:23.244] ----- Event: Jump Start: => Jumping : UPDATE
[LOG 18:48:23.245] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.245] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.245] State: Low G Bound (floating) : FIXEDUPDATE
[LOG 18:48:23.246] ----- Event: Low G bound land: => N/A : UPDATE
[LOG 18:48:23.246] ----- Event: Low G Bound Fall: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.247] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.247] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.248] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.248] State: Ragdoll : FIXEDUPDATE
[LOG 18:48:23.248] ----- Event: Recover Start: => Recover : FIXEDUPDATE
[LOG 18:48:23.249] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.249] State: Recover : FIXEDUPDATE
[LOG 18:48:23.250] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.250] ----- Event: Recover End: => N/A : UPDATE
[LOG 18:48:23.251] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.251] State: Jumping : FIXEDUPDATE
[LOG 18:48:23.251] ----- Event: Jump Launch: => Idle (Floating) : UPDATE
[LOG 18:48:23.252] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.252] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.253] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.253] State: Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.253] ----- Event: Landing: => N/A : UPDATE
[LOG 18:48:23.254] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.254] ----- Event: Pack Toggle: => N/A : UPDATE
[LOG 18:48:23.255] ----- Event: Feet Wet: => N/A : UPDATE
[LOG 18:48:23.255] ----- Event: Ladder Grab Start: => Ladder (Acquire) : UPDATE
[LOG 18:48:23.255] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.256] ----- Event: Boarding Part: => N/A : UPDATE
[LOG 18:48:23.256] ----- Event: Seat Board: => Seated (Command) : MANUAL_TRIGGER
[LOG 18:48:23.257] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.257] State: Landing : FIXEDUPDATE
[LOG 18:48:23.257] ----- Event: Landed: => Idle (Grounded) : UPDATE
[LOG 18:48:23.258] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.258] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.259] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.259] State: Swim (Idle) : FIXEDUPDATE
[LOG 18:48:23.260] ----- Event: Fall: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.260] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.260] ----- Event: Feet Dry: => N/A : UPDATE
[LOG 18:48:23.261] ----- Event: Swim Forward: => Swim (fwd) : UPDATE
[LOG 18:48:23.261] ----- Event: Ladder Grab Start: => Ladder (Acquire) : UPDATE
[LOG 18:48:23.262] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.262] ----- Event: Boarding Part: => N/A : UPDATE
[LOG 18:48:23.263] ----- Event: Seat Board: => Seated (Command) : MANUAL_TRIGGER
[LOG 18:48:23.263] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.264] State: Swim (fwd) : FIXEDUPDATE
[LOG 18:48:23.264] ----- Event: Fall: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.264] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.265] ----- Event: Feet Dry: => N/A : UPDATE
[LOG 18:48:23.265] ----- Event: Swim Stop: => Swim (Idle) : UPDATE
[LOG 18:48:23.266] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.266] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.266] State: Ladder (Acquire) : FIXEDUPDATE
[LOG 18:48:23.267] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.267] ----- Event: Ladder Grab Complete: => Ladder (Idle) : UPDATE
[LOG 18:48:23.268] ----- Event: Ladder End: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.268] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.269] State: Ladder (Idle) : UPDATE
[LOG 18:48:23.269] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.269] ----- Event: Ladder Climb: => Ladder (Climb) : UPDATE
[LOG 18:48:23.270] ----- Event: Ladder Descend: => Ladder (Descend) : UPDATE
[LOG 18:48:23.270] ----- Event: Ladder Let Go: => Idle (Floating) : UPDATE
[LOG 18:48:23.271] ----- Event: Ladder End: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.271] ----- Event: Ladder Lean (Start): => Ladder (Lean) : UPDATE
[LOG 18:48:23.272] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.272] ----- Event: Boarding Part: => N/A : UPDATE
[LOG 18:48:23.272] ----- Event: Seat Board: => Seated (Command) : MANUAL_TRIGGER
[LOG 18:48:23.273] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.273] State: Ladder (Lean) : FIXEDUPDATE
[LOG 18:48:23.274] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.274] ----- Event: Ladder End: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.275] ----- Event: Ladder Lean (End): => Ladder (Idle) : UPDATE
[LOG 18:48:23.275] ----- Event: Ladder Push Off Start: => Ladder (Pushoff) : UPDATE
[LOG 18:48:23.275] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.276] State: Ladder (Climb) : FIXEDUPDATE
[LOG 18:48:23.276] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.277] ----- Event: Ladder Descend: => Ladder (Descend) : UPDATE
[LOG 18:48:23.277] ----- Event: Ladder Stop: => Ladder (Idle) : UPDATE
[LOG 18:48:23.277] ----- Event: Ladder Let Go: => Idle (Floating) : UPDATE
[LOG 18:48:23.278] ----- Event: Ladder End: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.278] ----- Event: Clamber Grab Start: => Clamber (P1) : UPDATE
[LOG 18:48:23.279] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.279] State: Ladder (Descend) : FIXEDUPDATE
[LOG 18:48:23.280] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.280] ----- Event: Ladder Climb: => Ladder (Climb) : UPDATE
[LOG 18:48:23.281] ----- Event: Ladder Stop: => Ladder (Idle) : UPDATE
[LOG 18:48:23.281] ----- Event: Ladder Let Go: => Idle (Floating) : UPDATE
[LOG 18:48:23.281] ----- Event: Ladder End: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.282] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.282] State: Ladder (Pushoff) : FIXEDUPDATE
[LOG 18:48:23.283] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.283] ----- Event: Ladder Push Off Complete: => Idle (Floating) : FIXEDUPDATE
[LOG 18:48:23.284] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.284] State: Clamber (P1) : FIXEDUPDATE
[LOG 18:48:23.284] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.285] ----- Event: Clamber Reach P1: => Clamber (P2) : UPDATE
[LOG 18:48:23.285] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.286] State: Clamber (P2) : FIXEDUPDATE
[LOG 18:48:23.286] ----- Event: Clamber Reach P2: => Clamber (P3) : UPDATE
[LOG 18:48:23.287] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.287] State: Clamber (P3) : FIXEDUPDATE
[LOG 18:48:23.287] ----- Event: Clamber Reach P3: => Idle (Grounded) : UPDATE
[LOG 18:48:23.288] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.288] State: Flag-plant Terrain Acquire : FIXEDUPDATE
[LOG 18:48:23.289] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.289] ----- Event: Flag Plant Heading Acquired: => Planting Flag : FIXEDUPDATE
[LOG 18:48:23.289] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.290] State: Planting Flag : FIXEDUPDATE
[LOG 18:48:23.290] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.291] ----- Event: Flag Plant Complete: => Idle (Grounded) : UPDATE
[LOG 18:48:23.291] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.292] State: Seated (Command) : FIXEDUPDATE
[LOG 18:48:23.292] ----- Event: Stumble: => Ragdoll : MANUAL_TRIGGER
[LOG 18:48:23.293] ----- Event: Seat Deboard: => Idle (Floating) : MANUAL_TRIGGER
[LOG 18:48:23.293] ----- Event: Seat Eject: => Ragdoll : LATEUPDATE
[LOG 18:48:23.293] ----- Event: Grapple: => Grappled : MANUAL_TRIGGER

[LOG 18:48:23.294] State: Grappled : FIXEDUPDATE
[LOG 18:48:23.294] ----- Event: Grapple Release: => Ragdoll : LATEUPDATE

I used this code to get it: https://github.com/HappyFaceIndustries/KerbalAnimationSuite/blob/master/KerbalAnimationSuite/KerbalAnimationSuite.cs#L578

Edit: i fixed the link

I also released the plugin here: http://forum.kerbalspaceprogram.com/threads/130663

Edited by MrHappyFace
grammar
Link to comment
Share on other sites

I noticed that vessel.Landed = true in OnCollisionStay() forces the Kerbal to go through all the necessary states by himself. (Idle (Floating) -> Landing -> Landed -> Idle (Grounded))

This makes me believe that vessel.Landed is the true switch and that KFSMState are more of a kind of indicator which animation is used atm.

Link to comment
Share on other sites

Update: I think I got something semi-workable:

http://youtu.be/D_8auUInDXE

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);
}
}
}

That would be amazing if you made it! Also... what do I do with the code you provided? Because I have no idea what it means or where it goes. XD

Link to comment
Share on other sites

You'd need to compile it, though I think *Aqua* provided a pre-built plugin you can download of his version. My code is buggy "here, this kinda works: these are some of the quirks you'll come across" to another plugin coder, so I'd heavily advise against using it!

I think I'll be making the boots anyway, but it's oh so tempting to make a range of funky apparel....

Link to comment
Share on other sites

You'd need to compile it, though I think *Aqua* provided a pre-built plugin you can download of his version. My code is buggy "here, this kinda works: these are some of the quirks you'll come across" to another plugin coder, so I'd heavily advise against using it!

I think I'll be making the boots anyway, but it's oh so tempting to make a range of funky apparel....

Talking about apparel, I can make a wearable KIS model for you.

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...