Jump to content

Help with rotating part?


Recommended Posts

Also the default behavior doesn\'t let you attach anything to the secondary collider node that moves with the leg, only the main node which is in the 'anchor' or hinge, which you use to attach the leg to something else.

It will take a custom part for sure, and I am not sure whether someone can code a function that allows the VAB to recognize custom collider nodes to accept part connctions.

Hi,

I am trying to build a custom part that allows to be stacked (and stack things to it) but everything that is attached radially (surface) to be rotated at a fixed angle rate. to make it easier to build artificial gravity stuff, etc. (and maybe with tweekables change the angle rate)

I have been looking at infernal robotcs code and I got a basic part object (a cylinder) and a part subclass. The mesh does rotate but the things attached to the surface does not.

2014-02-03%2014_23_07-Unity%20-%20CentrifugeRotor.unity%20-%20KSPPlugins.png

the test vessel

2014-02-03%2014_37_21-Kerbal%20Space%20Program.png

the part code


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

public class ContinuousRotation : Part
{
public float Ammount = 1.0f;
public bool rotorActive = false;
private Transform rotor;

[KSPAction("Toggle Centrifuge")]
public void LockToggle(KSPActionParam param)
{
this.rotorActive= !this.rotorActive;
print(string.Format("ContinuousRotation rotorActive: {0}", this.rotorActive));
}

protected override void onPartLoad()
{
base.onPartLoad();
}

private void LogChilds(Transform parent){
print(string.Format("ContinuousRotation part is {0} and has {1} childs", parent.name, parent.childCount));
for(int i=0; i< parent.childCount; i++)
//print(string.Format("ContinuousRotation child {0} is {1} and has {2} childs", i, transform.GetChild(i).name, transform.GetChild(i).childCount));
this.LogChilds(parent.GetChild(i));
}

protected override void onPartStart(){
base.onPartStart();
if (vessel == null)
{
return;
}

this.LogChilds(transform);

rotor = transform.FindChild("model").FindChild("rotor");

if(rotor==null)
print(string.Format("ContinuousRotation rotor is NULL"));
else
print(string.Format("ContinuousRotation rotor: {0}", this.rotor.name));

for(int i=0; i< this.children.Count; i++){
print(string.Format("ContinuousRotation part {0} attachMode: {1}", this.children[i].name, this.children[i].attachMode));
if(this.children[i].attachMode == AttachModes.SRF_ATTACH){
print(string.Format("ContinuousRotation changing parentohood of {0} to {1}", this.children[i].name, this.rotor.name));
this.children[i].transform.parent = rotor;
this.children[i].attachMethod = AttachNodeMethod.HINGE_JOINT;
}
}

this.LogChilds(rotor);
}

protected override void onPartFixedUpdate(){
if(rotor == null)
return;
if(this.rotorActive){
if(this.rotor.childCount == 1){
for(int i=0; i< this.children.Count; i++){
//print(string.Format("ContinuousRotation part {0} attachMode: {1}", this.children[i].name, this.children[i].attachMode));
if(this.children[i].attachMode == AttachModes.SRF_ATTACH){
//print(string.Format("ContinuousRotation changing parentohood of {0} to {1}", this.children[i].name, this.rotor.name));
this.children[i].transform.parent = rotor;
this.children[i].attachMethod = AttachNodeMethod.HINGE_JOINT;
}
}
}
rotor.Rotate(Vector3.up * Ammount * TimeWarp.fixedDeltaTime, Space.Self);
print(string.Format("ContinuousRotation rotor.rotation: {0}, childs: {1}", rotor.localRotation.eulerAngles, rotor.childCount));

}
}
}

the part cfg (I borrowed, SAS cfg file)


PART
{
// this is a sample config file, for determining a good file format for defining part parameters
// comment line - ignored by cfg parser
// empty lines, or lines without a '=' sign are also ignored
// all other lines are split at the '=' sign, and the left operand is used to know what parameter we are setting
// diferent parameters require data in different formats (see docs), and each module has it's own parameters (again, see docs)
// each assignment must be in a single line. Lines without assignments will be ignored. (You CAN turn on word wrap, though)
// each keyword here relates to an existing variable in the assigned module. If the keyword isn't found, it is ignored.
// conversely, if a keyword is left unassigned (as in not in the file), it will be initialized with it's default value
// This is done automatically, so any public variable defined in the loaded module can be accessed this way (provided it's value can be parsed)


// --- general parameters ---
name = TCentrifugeRotor
module = ContinuousRotation
author = Tochas

// --- asset parameters ---
mesh = CentrifugeRotor.mu
scale = 1
rescaleFactor = 1

// --- node definitions ---
// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z
node_stack_bottom = 0.0, -0.5, 0.0, 0.0, 1.0, 0.0
node_stack_top = 0.0, 0.5, 0.0, 0.0, 1.0, 0.0

// --- FX definitions ---


// --- editor parameters ---
TechRequired = flightControl
entryCost = 3200
cost = 600
category = Control
subcategory = 0
title = Centrifuge Rotor
manufacturer = Tochas Space Voyages
description = For your artificial gravity needs.

// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 1,0,1,1,0

// --- standard part parameters ---
mass = 0.3
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.2
angularDrag = 2
crashTolerance = 9
maxTemp = 3400

//MODULE
//{
// name = ModuleReactionWheel

// PitchTorque = 20
// YawTorque = 20
// RollTorque = 20

// RESOURCE
// {
// name = ElectricCharge
// rate = 0.3
// }
//}

//MODULE
//{
// name = ModuleSAS
//}

}

what am I missing?

Thanks in advance for your help and guidance

source files

Link to comment
Share on other sites

Welcome to the community Tochas :)

I had to pop your post into it's own thread as the one you posed in originally was well over a year old, this way you should get the notice you need and no one complaining of necro posting.

Good luck with your part, it'd be really useful for space stations and similar and I look forwards to seeing it complete :)

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