/** * @brief Updates ball's movements and instantiates new ball objects when player press space. **/ public override void OnSyncedUpdate() { FP hor = (FP)TrueSyncInput.GetInt(INPUT_KEY_HORIZONTAL) / 100; FP ver = (FP)TrueSyncInput.GetInt(INPUT_KEY_VERTICAL) / 100; bool currentCreateState = TrueSyncInput.GetInt(INPUT_KEY_CREATE) == 1; // Instantiates a new ball belonging to current player if the following criteria is true if (!lastCreateState && currentCreateState && !createdRuntime) { SimpleControl otherSP = TrueSyncManager.SyncedInstantiate(prefab, tsTransform.position, tsTransform.rotation).GetComponent <SimpleControl>(); otherSP.createdRuntime = true; otherSP.owner = owner; lastCreateState = currentCreateState; return; } TSVector forceToApply = TSVector.zero; if (FP.Abs(hor) > FP.Zero) { forceToApply.x = hor / 3; } if (FP.Abs(ver) > FP.Zero) { forceToApply.z = ver / 3; } controlledBody.AddForce(forceToApply, ForceMode.Impulse); lastCreateState = currentCreateState; }
/** * @brief Updates player animations and movements. **/ public override void OnSyncedUpdate() { // Set a velocity based on player's speed and inputs TSVector velocity = tsRigidBody.velocity; if (TrueSyncInput.GetByte(INPUT_KEY_JUMP) > 0 && log) { startPosition = TrueSyncInput.GetTSVector(INPUT_MOUSE_POS); move = true; log = false; } if (TrueSyncInput.GetByte(INPUT_KEY_JUMP) < 1 && move) { endPosition = TrueSyncInput.GetTSVector(INPUT_MOUSE_POS); direction = endPosition - startPosition; velocity = direction / 10; move = false; log = true; } // Assigns this velocity as new player's linear velocity tsRigidBody.velocity = velocity; }
public override void OnSyncedUpdate() { bool goForward = TrueSyncInput.GetBool(FORWARD); bool goBackward = TrueSyncInput.GetBool(BACKWARD); bool goRight = TrueSyncInput.GetBool(RIGHT); bool goLeft = TrueSyncInput.GetBool(LEFT); if (goForward && !isCollide) { tsRigidBody.AddForce(TSVector.forward * forceFactor); } if (goBackward && !isCollide) { tsRigidBody.AddForce(TSVector.Negate(TSVector.forward) * forceFactor); } if (goRight && !isCollide) { tsRigidBody.AddForce(TSVector.right * forceFactor); } if (goLeft && !isCollide) { tsRigidBody.AddForce(TSVector.Negate(TSVector.right) * forceFactor); } isCollide = false; }
public override void OnSyncedUpdate() { if (TrueSyncInput.GetBool(3)) { thisBody.AddRelativeTorque(Torque); } }
public override void OnSyncedInput() { TrueSyncInput.SetBool(FORWARD, Input.GetKey(KeyCode.UpArrow)); TrueSyncInput.SetBool(BACKWARD, Input.GetKey(KeyCode.DownArrow)); TrueSyncInput.SetBool(RIGHT, Input.GetKey(KeyCode.RightArrow)); TrueSyncInput.SetBool(LEFT, Input.GetKey(KeyCode.LeftArrow)); }
public override void OnSyncedUpdate() { // receive click pos from input queue destination.x = TrueSyncInput.GetInt(MOUSE_X); destination.z = TrueSyncInput.GetInt(MOUSE_Y); UpdateShapes(); Steer(); }
public override void OnSyncedInput() { FP accell = Input.GetAxis("Vertical"); FP steer = Input.GetAxis("Horizontal"); TrueSyncInput.SetFP(0, accell); TrueSyncInput.SetFP(1, steer); }
public override void OnSyncedInput() { FP xAxis = Input.GetAxis("Horizontal"); FP zAxis = Input.GetAxis("Vertical"); TrueSyncInput.SetFP(HORIZONTAL, xAxis); TrueSyncInput.SetFP(VERTICAL, zAxis); }
/** * @brief Sets player inputs. **/ public override void OnSyncedInput() { int movement = (int)(Input.GetAxis("Horizontal") * 100); byte jump = Input.GetButton("Jump") ? (byte)1 : (byte)0; TrueSyncInput.SetInt(INPUT_KEY_MOVE, movement); TrueSyncInput.SetByte(INPUT_KEY_JUMP, jump); }
/** * * * /** * @brief Sets player inputs. **/ public override void OnSyncedInput() { byte jump = Input.GetButton("Fire1") ? (byte)1 : (byte)0; TSVector mPos = new TSVector(Input.mousePosition.x, 0, Input.mousePosition.y); TrueSyncInput.SetTSVector(INPUT_MOUSE_POS, mPos); // TrueSyncInput.SetFP(INPUT_MOUSE_Y, mY); TrueSyncInput.SetByte(INPUT_KEY_JUMP, jump); }
public override void OnSyncedUpdate() { base.OnSyncedUpdate(); FP hor = (FP)TrueSyncInput.GetInt(INPUT_KEY_HORIZONTAL) / 100; FP ver = (FP)TrueSyncInput.GetInt(INPUT_KEY_VERTICAL) / 100; bool currentCreateState = TrueSyncInput.GetBool(INPUT_KEY_CREATE); bool allowInput = false; if (hor != 0 || ver != 0) { allowInput = true; //Debug.Log("allow input is true: " + hor + " : " + ver); direction = new TSVector(hor, 0, ver); } //counter++; //if (counter > 10) //{ //Debug.Log("testing spine and pevlis"); if (allowInput) { //spring.AddForce(TSVector.down * 0); ball.AddForce(TSVector.down * 100); TSVector a = new TSVector(ver, 0, -hor); ball.angularVelocity = a * speedRatio; //Debug.Log(ball.angularVelocity + " a: " + a); if (ball.angularVelocity.magnitude > 50) { ball.angularVelocity = previousAngularVelocity; } previousAngularVelocity = ball.angularVelocity; UpdateRunPose(); } else { ball.angularVelocity = TSVector.zero; UpdateStandingPose(); } ////pelvis.angularVelocity = TSVector.zero; //pelvis.velocity = TSVector.zero; //pelvis.MovePosition(new TSVector(ball.position.x, pelvis.position.y, ball.position.z)); }
/** * @brief Sets player inputs. **/ public override void OnSyncedInput() { float hor = Input.GetAxis("Horizontal"); float ver = Input.GetAxis("Vertical"); bool space = Input.GetKey(KeyCode.Space); TrueSyncInput.SetInt(INPUT_KEY_HORIZONTAL, (int)(hor * 100)); TrueSyncInput.SetInt(INPUT_KEY_VERTICAL, (int)(ver * 100)); TrueSyncInput.SetBool(INPUT_KEY_CREATE, space); }
public override void OnSyncedInput() { TSVector movement = new TSVector((FP)Input.GetAxis("Horizontal"), 0, (FP)Input.GetAxis("Vertical")); TrueSyncInput.SetTSVector(INPUT_MOVE, movement); TrueSyncInput.SetInt(INPUT_FIRE, Input.GetButton("Fire1") ? 1 : 0); TrueSyncInput.SetTSVector(INPUT_LOOKAT, LookAtMouse()); }
// Collect any UI input that might of occured public override void OnSyncedInput() { TrueSyncInput.SetInt((byte)InputKey.LeftMelee, (leftMeleeKey) ? 1 : 0); leftMeleeKey = false; TrueSyncInput.SetInt((byte)InputKey.LeftRanged, (leftRangedKey) ? 1 : 0); leftRangedKey = false; TrueSyncInput.SetInt((byte)InputKey.RightMelee, (rightMeleeKey) ? 1 : 0); rightMeleeKey = false; TrueSyncInput.SetInt((byte)InputKey.RightRanged, (rightRangedKey) ? 1 : 0); rightRangedKey = false; }
public override void OnSyncedUpdate() { _mousePosition.x = TrueSyncInput.GetFP(MOUSE_X); _mousePosition.z = TrueSyncInput.GetFP(MOUSE_Y); _mouseClicked = TrueSyncInput.GetBool(MOUSE_CLICK); _keyPressed = TrueSyncInput.GetString(KEY_PRESS); StepRunning(); }
public override void OnSyncedInput() { if (Input.GetKeyDown(KeyCode.T)) { TrueSyncInput.SetBool(3, true); } else { TrueSyncInput.SetBool(3, false); } }
public override void OnSyncedInput() { if (Input.GetMouseButtonDown(0)) { TrueSyncInput.SetByte((byte)InputKey.SpawnCoin, 1); } else { TrueSyncInput.SetByte((byte)InputKey.SpawnCoin, 0); } }
public override void OnSyncedInput() { if (SpaceBattle.Instance.isBattleStart) { // 将飞船的位置和转向信息保存到 SyncedData 中以发送往 Server 同步到所有 Client TrueSyncInput.SetFP(0, _syncedInputManager.DeltaMovement.x); TrueSyncInput.SetFP(1, _syncedInputManager.DeltaMovement.y); TrueSyncInput.SetFP(2, _syncedInputManager.DeltaRotation.x); TrueSyncInput.SetFP(3, _syncedInputManager.DeltaRotation.y); } }
public override void OnSyncedInput() { if (Input.GetButton("Fire1")) { TrueSyncInput.SetByte(2, 1); } else { TrueSyncInput.SetByte(2, 0); } }
public override void OnSyncedUpdate() { FP accell = TrueSyncInput.GetFP(0); FP steer = TrueSyncInput.GetFP(1); accell *= 10 * TrueSyncManager.DeltaTime; steer *= 250 * TrueSyncManager.DeltaTime; tsTransform.Translate(0, 0, accell, Space.Self); tsTransform.Rotate(0, steer, 0); }
public override void OnSyncedInput() { FP accell = Input.GetAxis("Vertical"); FP steer = Input.GetAxis("Horizontal"); TrueSyncInput.SetFP(0, accell); TrueSyncInput.SetFP(1, steer); // Loger.LogFormat("OnSyncedInput inputIndex={0}", inputIndex); //inputIndex++; }
public override void OnSyncedInput() { TrueSyncInput.SetInt(INPUT_DIRECTION, requestDirection); TrueSyncInput.SetInt(INPUT_BUSTER, requestBuster); TrueSyncInput.SetInt(INPUT_CHIP, requestChip); TrueSyncInput.SetInt(INPUT_ENERGY, requestEnergy); TrueSyncInput.SetInt(INPUT_CHARGE, requestCharge); if (chip_hand != null) { TrueSyncInput.SetInt(INPUT_HELD, chip_hand.held); } }
/** * @brief Updates ball's movements and instantiates new ball objects when player press space. **/ public override void OnSyncedUpdate() { TSVector tapLocation = TrueSyncInput.GetTSVector(INPUT_TAP_LOCATION); // Take tapLocation and calculate what to do if (tapLocation != TSVector.zero) { OnTapLocation(tapLocation); } UpdatePlayerPosition(); }
void Movement() { TSVector movement = TrueSyncInput.GetTSVector(INPUT_MOVE); TSVector velocity = rigidBody.velocity; velocity.y = 0; rigidBody.velocity = movement * MovementSpeed; //rigidBody.AddForce (movement * MovementSpeed - velocity, ForceMode.Impulse); }
public override void OnSyncedUpdate() { FP accell = TrueSyncInput.GetFP(0); FP steer = TrueSyncInput.GetFP(1); accell *= 10 * TrueSyncManager.DeltaTime; steer *= 250 * TrueSyncManager.DeltaTime; tsTransform.Translate(0, 0, accell, Space.Self); tsTransform.Rotate(0, steer, 0); // Loger.LogFormat("OnSyncedUpdate updateIndex={0}", updateIndex); //updateIndex++; }
public override void OnSyncedUpdate() { Movement(); Gravity(); tsTransform.LookAt(TrueSyncInput.GetTSVector(INPUT_LOOKAT)); if (TrueSyncInput.GetInt(INPUT_FIRE) == 1 && canFire) { Fire(); } }
// TrueSyncBehaviour's interface public override void OnSyncedInput() { base.OnSyncedInput(); // Clear temp structure. m_Input.Clear(); // Fill temp structure. m_PlayerSyncedInput.Step(m_Input); // Write TrueSyncInput. // FP for (int fpIndex = 0; fpIndex < m_Input.fpCount; ++fpIndex) { tnInput.FPInput fpInput; bool found = m_Input.GetFPInput(fpIndex, out fpInput); if (found) { TrueSyncInput.SetFP(fpInput.key, fpInput.value); } } // Int for (int intIndex = 0; intIndex < m_Input.intCount; ++intIndex) { tnInput.IntInput intInput; bool found = m_Input.GetIntInput(intIndex, out intInput); if (found) { TrueSyncInput.SetInt(intInput.key, intInput.value); } } // Bytes for (int byteIndex = 0; byteIndex < m_Input.byteCount; ++byteIndex) { tnInput.ByteInput byteInput; bool found = m_Input.GetByteInput(byteIndex, out byteInput); if (found) { TrueSyncInput.SetByte(byteInput.key, byteInput.value); } } }
public override void OnSyncedUpdate() { base.OnSyncedUpdate(); if (!m_RunSyncedUpdate) { return; } // Read delta time. FP deltaTime = TrueSyncManager.deltaTimeMain; // Update timers. UpdateTimers(deltaTime); // Handle actions. bool buttonDown = TrueSyncInput.HasByte(m_ButtonDownCode); if (buttonDown && (m_Timer == FP.Zero)) { int tick = TrueSyncManager.ticksMain; if (!m_EffectTicks.Contains(tick)) { if (m_Pivot != null) { EffectUtils.PlayEffect(m_Effect, m_Pivot); } m_EffectTicks.Add(tick); } m_Timer = m_Cooldown; } // Clear effect ticks cache. for (int index = 0; index < m_EffectTicks.Count; ++index) { int tick = m_EffectTicks[index]; if (TrueSyncManager.IsTickOutOfRollbackMain(tick)) { m_EffectTicks.RemoveAt(index); index = -1; } } }
public override void OnSyncedUpdate() { _movX = TrueSyncInput.GetFP(0); _movY = TrueSyncInput.GetFP(1); _rotX = TrueSyncInput.GetFP(2); _rotY = TrueSyncInput.GetFP(3); Debug.Log("move:" + new Vector2(_movX.AsFloat(), _movY.AsFloat()) + "rot:" + new Vector2(_rotX.AsFloat(), _rotY.AsFloat())); // 移动 Move(); // 开火 Fire(); }
/** * @brief Sets player inputs. **/ public override void OnSyncedInput() { int input = 0; if (Input.GetKey(KeyCode.LeftArrow)) { input = -1; } else if (Input.GetKey(KeyCode.RightArrow)) { input = 1; } TrueSyncInput.SetInt(INPUT_KEY_HORIZONTAL, input); }