Question by
baegyutae0407 · Jan 06 at 07:11 AM ·
scripting problemcodepage
No input keys but moving?
so i have this code right now that allows to move up and down when G,H is pressed but i have no idea how G and H was set without Get.Key or any mention of G, H in the code
public enum BigHandState { Fixed = 0, MovingUp = 1, MovingDown = -1 };
public BigHandState moveState = BigHandState.Fixed;
public float speed = 1.0f;
private void FixedUpdate()
{
if (moveState != BigHandState.Fixed)
{
ArticulationBody articulation = GetComponent<ArticulationBody>();
//get jointPosition along y axis
float xDrivePostion = articulation.jointPosition[0];
Debug.Log(xDrivePostion);
//increment this y position
float targetPosition = xDrivePostion + -(float)moveState * Time.fixedDeltaTime * speed;
//set joint Drive to new position
var drive = articulation.xDrive;
drive.target = targetPosition;
articulation.xDrive = drive;
}
}
}
and
public GameObject hand;
void Update()
{
float input = Input.GetAxis("BigHandVertical");
BigHandState moveState = MoveStateForInput(input);
GripperDemoController controller = hand.GetComponent<GripperDemoController>();
controller.moveState = moveState;
}
BigHandState MoveStateForInput(float input)
{
if (input > 0)
{
return BigHandState.MovingUp;
}
else if (input < 0)
{
return BigHandState.MovingDown;
}
else
{
return BigHandState.Fixed;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Need help with physics base enemy AI movement 1 Answer
Problem with script? 0 Answers
Call animation only once? 1 Answer
Player rotation always resets. 0 Answers
Code error :/ 1 Answer