void setState(EntityPlayer entity, EntityMotor motor, WALLRIDE_STATE state) { if (state == WALLRIDE_STATE.INACTIVE) { if (m_wallRideState == WALLRIDE_STATE.CLIMBING) { Debug.Log("NUDGE"); motor.Rigidbody.AddForce(Vector3.up * m_climbEndNudgeForce, ForceMode.Impulse); } } if (state == WALLRIDE_STATE.CLIMBING || state == WALLRIDE_STATE.SLIDING) { if (entity.useResource(activationCost, false) < activationCost) { return; } motor.Rigidbody.velocity = Vector3.zero; motor.isUpdateGravity = false; motor.isUpdateMovement = false; } else { motor.isUpdateGravity = true; motor.isUpdateMovement = true; } m_wallRideState = state; }
public void hold(EntityPlayer entity, EntityMotor motor) { if (!m_isReceiveInput) { return; } }
public override void kFixedUpdate(EntityPlayer entity, EntityMotor motor, Avatar avatar, float timeElapsed) { base.kFixedUpdate(entity, motor, avatar, timeElapsed); if (!isUse) { return; } Vector3 dir = (m_dirHorizontal + m_dirVertical).normalized; Vector3 velocityDesired = dir * m_speed; Vector3 velocityDiff = velocityDesired - motor.Rigidbody.velocity; //motor.Rigidbody.AddForce(-Physics.gravity); motor.Rigidbody.AddForce(velocityDiff * Mathf.Min(1.0f, timeElapsed * m_timeAcceleration), ForceMode.Impulse); float fuelCost = (velocityDiff * Mathf.Min(1.0f, timeElapsed * m_timeAcceleration)).magnitude; fuelCost = m_resourcePerSecond * timeElapsed; if (entity.useResource(fuelCost, true) < fuelCost) { setActive(entity, motor, false); Debug.Log("NO MORE FUEL"); } //motor.Rigidbody.velocity -= motor.Rigidbody.velocity *Mathf.Min(1, m_airResistance * timeElapsed); //motor.Rigidbody.MovePosition(motor.transform.position + dir * m_speed * timeElapsed); // motor.Rigidbody.AddForce(-motor.Rigidbody.velocity*500*timeElapsed); // motor.Rigidbody.AddForce(movementDirection * speed* motor.m_entity.getModSpeed() * timeElapsed ); }
public void end(EntityPlayer entity, EntityMotor motor, Avatar avatar) { if (!m_isReceiveInput) { return; } endProcess(entity, motor, avatar); }
// Use this for initialization protected override void Start() { m_controller = new PlayerController(this); m_motor = new EntityMotor(this); m_body = GetComponent<CharacterController>(); m_speed = 10f; }
void hprLink(EntityMotor motor, List <Action> from, List <Action> to) { for (int i = 0; i < from.Count; i++) { from[i].init(motor); to.Add(from[i]); } }
void hprUnLink(EntityMotor motor, List <Action> from, List <Action> to) { for (int i = 0; i < from.Count; i++) { from[i].unInit(motor); to.Remove(from[i]); } }
public override void endProcess(EntityPlayer entity, EntityMotor motor, Avatar avatar) { base.endProcess(entity, motor, avatar); if (!isUse) { return; } setActive(entity, motor, false); }
public override void useProcess(EntityPlayer entity, EntityMotor motor, Avatar avatar) { base.use(entity, motor, avatar); if (isUse) { return; } setActive(entity, motor, true); }
private void Awake() { spriteRenderer = GetComponent <SpriteRenderer> (); rb = GetComponent <Rigidbody2D> (); playerInput = GetComponent <PlayerInput> (); playerInputHandler = new PlayerInputHandler(playerInput); entityMotor = new EntityMotor(playerInputHandler, rb, speed); playerInteractHandler = new PlayerInteractHandler(playerInputHandler); }
// Use this for initialization protected virtual void Start() { m_controller = new EntityController(this); m_motor = new EntityMotor(this); m_body = GetComponent<CharacterController>(); Debug.Log ("m_controller = " + m_controller); Debug.Log ("m_motor = " + m_motor); Debug.Log ("m_body = " + m_body); }
public void KUpdate(EntityPlayer entity, EntityMotor motor, Avatar m_avatar, float timeElapsed) { if (entity == null) { return; } motor.move(entity, m_avatar, entity.Speed, Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); motor.rotate(this.transform, m_avatar.m_head.transform, entity.RotationSpeed, Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); //move(m_rigidbody,m_speedMove, Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), timeElapsed); //rotate(m_rigidbody, m_avatar,m_speedRotate, Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); updateMotorInput(entity, motor, m_avatar); }
public void unLink(EntityMotor motor) { hprUnLink(motor, m_actPassive, motor.m_actPassive); hprUnLink(motor, m_actJump, motor.m_actJump); hprUnLink(motor, m_actLMB, motor.m_actLMB); hprUnLink(motor, m_actRMB, motor.m_actRMB); hprUnLink(motor, m_actR, motor.m_actR); hprUnLink(motor, m_actF, motor.m_actF); hprUnLink(motor, m_actShift, motor.m_actShift); hprUnLink(motor, m_actE, motor.m_actE); hprUnLink(motor, m_actQ, motor.m_actQ); }
public virtual void kUpdate(EntityPlayer entity, EntityMotor motor, Avatar avatar, float timeElapsed) { if (m_isReady) { return; } m_delayTimeElapsed += timeElapsed; if (m_delayTimeElapsed > m_delayMax) { m_isReady = true; m_delayTimeElapsed = 0; } }
public override void kUpdate(EntityPlayer entity, EntityMotor motor, Avatar avatar, float timeElapsed) { base.kUpdate(entity, motor, avatar, timeElapsed); if (m_wallRideState == WALLRIDE_STATE.INACTIVE) { return; } //Debug.Log("" + m_wallRideState); if (m_wallRideState == WALLRIDE_STATE.READY) { udpateFindWall(entity, motor, avatar, timeElapsed); return; } if (m_wallRideState == WALLRIDE_STATE.CLIMBING) { Vector3 velo = new Vector3(m_wallDirection.x, 1, m_wallDirection.z) * entity.Speed * m_speedWallRiding; motor.Rigidbody.MovePosition(motor.transform.position + velo * timeElapsed); Vector3 previousWallNormal = m_wallNormal; if (!hprFindWall(avatar.transform.position, m_wallDirection, m_wallFindRadius)) { setState(entity, motor, WALLRIDE_STATE.INACTIVE); return; } if (1 - Vector3.Dot(previousWallNormal, m_wallNormal) > normalAllowance) { setState(entity, motor, WALLRIDE_STATE.INACTIVE); return; } } if (m_wallRideState == WALLRIDE_STATE.SLIDING) { Vector3 forwardDir = Vector3.Cross(m_wallNormal, new Vector3(0, 1, 0)); //forwardDir.y = 0; forwardDir.Normalize(); Vector3 velo = (new Vector3(m_wallDirection.x, 0, m_wallDirection.z) + forwardDir) * entity.Speed * m_speedWallRiding; motor.Rigidbody.MovePosition(motor.transform.position + velo * timeElapsed); Vector3 previousWallNormal = m_wallNormal; if (!hprFindWall(avatar.transform.position, m_wallDirection, m_wallFindRadius)) { setState(entity, motor, WALLRIDE_STATE.INACTIVE); return; } if (1 - Vector3.Dot(previousWallNormal, m_wallNormal) > normalAllowance) { setState(entity, motor, WALLRIDE_STATE.INACTIVE); return; } } }
public override void kFixedUpdate(EntityPlayer entity, EntityMotor motor, Avatar m_avatar, float timeElapsed) { // Debug.Log(isActivated); if (!isUse) { return; } base.kUpdate(entity, motor, m_avatar, timeElapsed); //motor.Rigidbody.AddForce(-Physics.gravity); if (isActivated) { motor.IsGrounded = false; //Vector3 bodyVelocity = new Vector3(motor.Rigidbody.velocity.x,0, motor.Rigidbody.velocity.z); //motor.Rigidbody.velocity -= motor.Rigidbody.velocity * Mathf.Min(1, m_airResistance * timeElapsed); Vector3 dirFly = (motor.Velocity).normalized; float bodyDownwardForce = Mathf.Min(m_forceAdjustmentMax, Mathf.Max(0, -motor.Rigidbody.velocity.y)); Vector3 bodyVelocity = new Vector3(motor.Rigidbody.velocity.x, 0, motor.Rigidbody.velocity.z); //if(bodyDownwardForce>0.1f) Debug.Log(bodyDownwardForce); float forceUpward = m_forceUpward; motor.Rigidbody.AddForce(Vector3.up * forceUpward * timeElapsed, ForceMode.Impulse); motor.Rigidbody.AddForce(Vector3.up * bodyDownwardForce * Mathf.Min(1, m_forceAdjustmentTimeAcceleration * timeElapsed), ForceMode.Impulse); Vector3 stablize = Vector3.zero; if (motor.Velocity.magnitude != 0) { Vector3 desiredVelocity = motor.VelocityDirHorizontal * m_velocityHorizontal; Vector3 desiredVelocityDir = desiredVelocity.normalized; desiredVelocity = desiredVelocityDir * Mathf.Max(desiredVelocity.magnitude, Vector3.Dot(bodyVelocity, desiredVelocity.normalized)); stablize = (desiredVelocity - bodyVelocity); //Debug.Log("STABLIZE " + stablize); motor.Rigidbody.AddForce(stablize * Mathf.Min(1, m_forceAdjustmentTimeAcceleration * timeElapsed), ForceMode.Impulse); } float resourceRequired = (Vector3.up * forceUpward * timeElapsed).magnitude + (Vector3.up * bodyDownwardForce * Mathf.Min(1, m_forceAdjustmentTimeAcceleration * timeElapsed)).magnitude + (stablize * Mathf.Min(1, 1.5f * timeElapsed)).magnitude; resourceRequired *= m_resourceUseRate; float resourceUsed = entity.useResource(resourceRequired, true); //Debug.Log("USED FUEL " + resourceRequired); if (resourceUsed < resourceRequired) { setActive(entity, motor, false); } //motor.Rigidbody.AddForce(-motor.Rigidbody.velocity * 0.9f); //motor.Rigidbody.AddForce(dirFly * m_force * timeElapsed, ForceMode.Impulse); } // motor.Rigidbody.AddForce(-motor.Rigidbody.velocity*500*timeElapsed); // motor.Rigidbody.AddForce(movementDirection * speed* motor.m_entity.getModSpeed() * timeElapsed ); }
public void setActive(EntityPlayer entity, EntityMotor motor, bool value) { entity.m_isRegenResource = !value; if (value) { isUse = true; isActivated = false; m_timeElapsed = 0; } else { isUse = false; m_timeElapsed = 0; activate(motor, false); } }
public void link(EntityMotor motor) { this.transform.parent = motor.transform; this.transform.localPosition = Vector3.zero; this.transform.localRotation = Quaternion.identity; hprLink(motor, m_actPassive, motor.m_actPassive); hprLink(motor, m_actJump, motor.m_actJump); hprLink(motor, m_actLMB, motor.m_actLMB); hprLink(motor, m_actRMB, motor.m_actRMB); hprLink(motor, m_actR, motor.m_actR); hprLink(motor, m_actF, motor.m_actF); hprLink(motor, m_actShift, motor.m_actShift); hprLink(motor, m_actE, motor.m_actE); hprLink(motor, m_actQ, motor.m_actQ); }
/* * * */ public override void kUpdate(EntityPlayer entity, EntityMotor motor, Avatar avatar, float timeElapsed) { // Debug.Log(motor.isUpdateMovement); if (!isUse) { return; } m_timeElapsed += timeElapsed; if (m_timeElapsed < m_minHoldTime) { return; } activate(motor, true); //Debug.Log("FLYING"); //base.kUpdate(motor, timeElapsed); //motor.Rigidbody.AddForce(-Physics.gravity *2.0f * timeElapsed); }
void udpateFindWall(EntityPlayer entity, EntityMotor motor, Avatar avatar, float timeElapsed) { Debug.Log("Looking for a wall"); if (isClimbVertical) { if (hprFindWall(avatar.transform.position, avatar.transform.forward, m_wallFindRadius)) { setState(entity, motor, WALLRIDE_STATE.CLIMBING); return; } } if (isClimbHorizontal) { if (hprFindWall(avatar.transform.position, avatar.transform.right, m_wallFindRadius) || hprFindWall(avatar.transform.position, -avatar.transform.right, m_wallFindRadius)) { setState(entity, motor, WALLRIDE_STATE.SLIDING); } } }
public override void useProcess(EntityPlayer entity, EntityMotor motor, Avatar avatar) { base.use(entity, motor, avatar); var dir = motor.VelocityRelativeDir.z * avatar.Look + motor.VelocityRelativeDir.x * avatar.Right; if (motor.IsGrounded) { dir.y = 0; dir.Normalize(); dir.y = 1; dir.Normalize(); } if (dir.magnitude == 0) { dir = Vector3.up; } var force = dir * m_forceUsed; Debug.Log(avatar.Look); Debug.Log("MOTOR VELO " + motor.VelocityDirHorizontal); Debug.Log(force); motor.Rigidbody.AddForce(force, ForceMode.Impulse); }
public void use(EntityPlayer entity, EntityMotor motor, Avatar avatar) { if (!m_isReceiveInput) { return; } if (!m_isReady) { return; } m_isReady = false; bool canUse = true; if (m_ammoIsNeeded && entity.useAmmoTest(m_ammoRequired, m_ammoIsStream) == 0) { canUse = false; } if (m_resourceIsNeeded && entity.useResourceTest(m_resourceRequired, m_resourceIsStream) == 0) { canUse = false; } if (!canUse) { return; } if (m_ammoIsNeeded) { entity.useAmmo(m_ammoRequired, m_ammoIsStream); } if (m_resourceIsNeeded) { entity.useResource(m_resourceRequired, m_resourceIsStream); } useProcess(entity, motor, avatar); }
void doEntityAction(Tile[] adjacentTiles) { for (int i = 0; i < 4; i++) { if (adjacentTiles[i] != null) { Tile _tile = adjacentTiles[i]; _tile.isSelected = false; if (_tile.ContainsEntityLayer(Layers.Pushable)) { EntityMotor _entityMotor = _tile.GetEntityByLayer(Layers.Pushable).GetComponent <EntityMotor>(); if (i == 0) // if Toptile { //_entityMotor.MoveAmount = 0; _entityMotor.Move(Vector3.forward); } else if (i == 1) //if RightTile { //_entityMotor.MoveAmount = 0; _entityMotor.Move(Vector3.right); } else if (i == 2) //if BottomTile { //_entityMotor.MoveAmount = 0; _entityMotor.Move(Vector3.back); } else if (i == 3) //if LeftTile { //_entityMotor.MoveAmount = 0; _entityMotor.Move(Vector3.left); } } } } }
void setActive(EntityPlayer entity, EntityMotor motor, bool value) { if (!value) { entity.m_isRegenResource = true; isUse = false; m_dirHorizontal = Vector3.zero; motor.isUpdateMovement = true; motor.m_evntMoves.Remove(flyHorizontally); motor.m_evntJump.Remove(flyUp); motor.m_evntJumpStop.Remove(flyUpDownStop); motor.m_evntCrawlBegin.Remove(flyDown); motor.m_evntCrawlEnd.Remove(flyUpDownStop); DEL.RAISE(m_evntFlyEnd, entity, motor); } else { if (entity.useResource(m_resourceActivation, false) == 0) { //Activation cost is not paid. //Activation failed. return; } entity.m_isRegenResource = false; isUse = true; motor.isUpdateMovement = false; motor.m_evntMoves.Add(flyHorizontally); motor.m_evntJump.Add(flyUp); motor.m_evntJumpStop.Add(flyUpDownStop); motor.m_evntCrawlBegin.Add(flyDown); motor.m_evntCrawlEnd.Add(flyUpDownStop); DEL.RAISE(m_evntFlyBegin, entity, motor); } }
void hdr_jump(EntityPlayer entity, EntityMotor motor, Avatar avatar, float horizontal, float vertical) { }
private void Awake() { motor = GetComponent <EntityMotor> (); }
public override void useProcess(EntityPlayer entity, EntityMotor motor, Avatar avatar) { base.useProcess(entity, motor, avatar); Player.LOCAL_PLAYER.CmdFireRocket(avatar.m_head.transform.position, avatar.m_head.transform.position + avatar.m_head.transform.forward); }
void flyUp(EntityPlayer entity, EntityMotor motor, Avatar avatar, float horizontal, float vertical) { m_dirVertical = Vector3.up; }
void flyUpDownStop(EntityPlayer entity, EntityMotor motor) { m_dirVertical = Vector3.zero; }
void flyDown(EntityPlayer entity, EntityMotor motor) { m_dirVertical = Vector3.down; }
public override void useProcess(EntityPlayer entity, EntityMotor motor, Avatar avatar) { base.useProcess(entity, motor, avatar); setState(entity, motor, WALLRIDE_STATE.READY); }
public override void endProcess(EntityPlayer entity, EntityMotor motor, Avatar avatar) { base.endProcess(entity, motor, avatar); setState(entity, motor, WALLRIDE_STATE.INACTIVE); }