public override void FixedUpdate(float fixedDeltaTime) { if (CurrentState == State.IsMoving) { CharacterTransform.Translate(moveDirection * MoveSpeed); CharacterTransform.position = new Vector3(Mathf.Clamp(CharacterTransform.position.x, minX, maxX), CharacterTransform.position.y, Mathf.Clamp(CharacterTransform.position.z, minZ, maxZ)); } }
protected new void Update() { base.Update(); CharacterTransform.Translate(direction * moveSpeed * Time.deltaTime, Space.World); jumpCtrl(); handCtrl(); shoulderCtrl(); }
protected void jumpCtrl() { if (isJumping) { //Debug.Log(speedUp); speedUp -= grav * Time.deltaTime; //Debug.Log("im jumping"); if (CharacterTransform.transform.position.y < initPosY) { isJumping = false; speedUp = Vector3.zero; CharacterTransform.Translate(new Vector3(CharacterTransform.position.x, initPosY, CharacterTransform.position.z) - CharacterTransform.position, Space.World); } } }
public CharacterModel(GameObject prefab, CharacterData characterData, Vector3 groundPosition) { CharacterData = characterData; CharacterCommonSettings = CharacterData._characterCommonSettings; CharacterStatsSettings = CharacterData._characterStatsSettings; CharacterTransform = prefab.transform; CharacterTransform.rotation = Quaternion.Euler(0, CharacterCommonSettings.InstantiateDirection, 0); CharacterTransform.name = CharacterCommonSettings.InstanceName; CharacterTransform.tag = CharacterCommonSettings.InstanceTag; CharacterTransform.gameObject.layer = CharacterCommonSettings.InstanceLayer; Transform[] children = CharacterTransform.GetComponentsInChildren <Transform>(); foreach (var child in children) { child.gameObject.layer = CharacterCommonSettings.InstanceLayer; } if (prefab.GetComponent <Rigidbody>() != null) { CharacterRigitbody = prefab.GetComponent <Rigidbody>(); } else { CharacterRigitbody = prefab.AddComponent <Rigidbody>(); CharacterRigitbody.freezeRotation = true; CharacterRigitbody.mass = CharacterCommonSettings.RigitbodyMass; CharacterRigitbody.drag = CharacterCommonSettings.RigitbodyDrag; CharacterRigitbody.angularDrag = CharacterCommonSettings.RigitbodyAngularDrag; } CharacterRigitbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; if (prefab.GetComponent <CapsuleCollider>() != null) { CharacterCapsuleCollider = prefab.GetComponent <CapsuleCollider>(); } else { CharacterCapsuleCollider = prefab.AddComponent <CapsuleCollider>(); CharacterCapsuleCollider.center = CharacterCommonSettings.CapsuleColliderCenter; CharacterCapsuleCollider.radius = CharacterCommonSettings.CapsuleColliderRadius; CharacterCapsuleCollider.height = CharacterCommonSettings.CapsuleColliderHeight; } CharacterCapsuleCollider.transform.position = groundPosition; if (prefab.GetComponent <SphereCollider>() != null) { CharacterSphereCollider = prefab.GetComponent <SphereCollider>(); CharacterSphereCollider.isTrigger = true; } else { CharacterSphereCollider = prefab.AddComponent <SphereCollider>(); CharacterSphereCollider.center = CharacterCommonSettings.SphereColliderCenter; CharacterSphereCollider.radius = CharacterCommonSettings.SphereColliderRadius; CharacterSphereCollider.isTrigger = true; } CameraTarget = Services.SharedInstance.CameraService.CreateCameraTarget(CharacterTransform); CameraTargetTransform = CameraTarget.transform; TargetMarkBasePosition = new Vector3(CharacterTransform.localPosition.x, CharacterTransform.localPosition.y + CharacterCapsuleCollider.height + CharacterCommonSettings.TargetMarkHeight, CharacterTransform.localPosition.z); TargetMark = CharacterCommonSettings.CreateTargetMark(CharacterTransform, TargetMarkBasePosition); TargetMarkTransform = TargetMark.transform; if (prefab.GetComponent <Animator>() != null) { CharacterAnimator = prefab.GetComponent <Animator>(); } else { CharacterAnimator = prefab.AddComponent <Animator>(); } CharacterAnimator.runtimeAnimatorController = CharacterCommonSettings.CharacterAnimator; CharacterAnimator.applyRootMotion = false; if (prefab.GetComponent <PlayerBehavior>() != null) { PlayerBehavior = prefab.GetComponent <PlayerBehavior>(); } else { PlayerBehavior = prefab.AddComponent <PlayerBehavior>(); } PlayerBehavior.SetType(InteractableObjectType.Player); PlayerBehavior.Stats = CharacterStatsSettings; EnemiesInTrigger = new List <Collider>(); ClosestEnemy = null; IsMoving = false; IsGrounded = false; IsEnemyNear = false; IsInBattleMode = false; IsWeaponInHands = false; CurrentSpeed = 0; AnimationSpeed = CharacterData._characterCommonSettings.AnimatorBaseSpeed; LeftHand = CharacterTransform.Find(CharacterCommonSettings.LeftHandObjectPath); RightHand = CharacterTransform.Find(CharacterCommonSettings.RightHandObjectPath); LeftFoot = CharacterTransform.Find(CharacterCommonSettings.LeftFootObjectPath); RightFoot = CharacterTransform.Find(CharacterCommonSettings.RightFootObjectPath); //SphereCollider LeftFootTrigger = LeftFoot.gameObject.AddComponent<SphereCollider>(); //LeftFootTrigger.radius = CharacterCommonSettings.LeftFootHitBoxRadius; //LeftFootTrigger.isTrigger = true; //LeftFoot.gameObject.AddComponent<Rigidbody>().isKinematic = true; //LeftFootBehavior = LeftFoot.gameObject.AddComponent<WeaponHitBoxBehavior>(); //LeftFootBehavior.SetType(InteractableObjectType.HitBox); //LeftFootBehavior.IsInteractable = false; //SphereCollider RightFootTrigger = RightFoot.gameObject.AddComponent<SphereCollider>(); //RightFootTrigger.radius = CharacterCommonSettings.RightFootHitBoxRadius; //RightFootTrigger.isTrigger = true; //RightFoot.gameObject.AddComponent<Rigidbody>().isKinematic = true; //RightFootBehavior = RightFoot.gameObject.AddComponent<WeaponHitBoxBehavior>(); //RightFootBehavior.SetType(InteractableObjectType.HitBox); //RightFootBehavior.IsInteractable = false; LeftHandWeapon = null; RightHandWeapon = null; LeftHandWeaponObject = null; RightHandWeaponObject = null; Services.SharedInstance.CameraService.Initialise(this); }
private void GetDirection() { #region move through keyboard // reset to 0 speedForward = Vector3.zero; speedBack = Vector3.zero; speedLeft = Vector3.zero; speedRight = Vector3.zero; //speedUp = Vector3.zero; speedDown = Vector3.zero; // get keyboard input if (Input.GetKey(KeyCode.W)) { speedForward = CharacterTransform.forward; } if (Input.GetKey(KeyCode.S)) { speedBack = -CharacterTransform.forward; } if (Input.GetKey(KeyCode.A)) { speedLeft = -CharacterTransform.right; } if (Input.GetKey(KeyCode.D)) { speedRight = CharacterTransform.right; } if (Input.GetKey(KeyCode.Space) && !isJumping) { if (jumpStrength < maxStrength) { ++jumpStrength; } } else if (!Input.GetKey(KeyCode.Space) && jumpStrength > 10 && !isJumping) { isJumping = true; initPosY = CharacterTransform.transform.position.y; originJumpSpeed = jumpStrength / 20.0f; //Debug.Log(CharacterTransform.up); speedUp = CharacterTransform.up * (jumpStrength / 20.0f); jumpStrength = 0; } direction = speedForward + speedBack + speedLeft + speedRight + speedUp + speedDown; #endregion #region rotate // camera toward CharacterTransform.RotateAround(CharacterTransform.position, Vector3.up, Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime); //CharacterTransform.RotateAround(CharacterTransform.position, CharacterTransform.right, -Input.GetAxis("Mouse Y") * rotateSpeed * Time.deltaTime); // change direction direction = V3RotateAround(direction, Vector3.up, Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime); //direction = V3RotateAround(direction, CharacterTransform.right, -Input.GetAxis("Mouse Y") * rotateSpeed * Time.deltaTime); #endregion }
void Process() { //need a clean buffer //when drawing if (buffer != null) { buffer.Release(); buffer = null; } if (processor == null || lines == null) { return; } CreateBufferIfNeeded(); processor.Prepare(width, height, character, buffer); float px = 1.0f / width; float py = 1.0f / height; MVector pivot = new MVector(-1, 0); if (map != null && map.Count > 0 && transforms.Count > 0) { int tindex = 0; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; float left = 0; float alignmentAdjustment = adjustments[i]; for (int j = 0; j < line.Length; j++) { if (tindex >= transforms.Count) { continue; } string ch = line.Substring(j, 1); FontManager.CharData data = null; if (map.TryGetValue(ch, out data)) { if (data.texture == null) { tindex++; continue; } CharacterTransform ct = transforms[tindex]; MVector finalPos = new MVector((ct.position.X + left * ct.scale.X) * width - alignmentAdjustment, (ct.position.Y + (i * data.bearing) * py * ct.scale.Y) * height); left += (data.size.X + pspacing) * px; character.Bind(); character.SetData(data.texture.Image, GLInterfaces.PixelFormat.Bgra, (int)Math.Ceiling(data.size.X), (int)Math.Ceiling(data.size.Y)); GLTextuer2D.Unbind(); processor.Translation = finalPos; processor.Angle = ct.angle; processor.Pivot = pivot; processor.Scale = ct.scale * (new MVector(data.size.X, data.size.Y) * 0.5f); processor.ProcessCharacter(width, height, character, buffer); } tindex++; } } } processor.Complete(); Updated(); Output.Data = buffer; Output.Changed(); }
private void GetTransforms() { transforms.Clear(); if (map == null || map.Count == 0) { return; } adjustments.Clear(); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; float alignmentAdjustment = 0; for (int j = 0; j < line.Length; j++) { string ch = line.Substring(j, 1); FontManager.CharData data = null; MVector pPos = position; float pcharRotation = rotation; MVector pScale = scale; if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Rotation")) { if (ParentGraph.IsParameterValueFunction(Id, "Rotation")) { FunctionGraph func = ParentGraph.GetParameterRaw(Id, "Rotation").Value as FunctionGraph; func.SetVar("character", j, NodeType.Float); func.SetVar("maxCharacters", line.Length, NodeType.Float); func.SetVar("line", i, NodeType.Float); func.SetVar("maxLines", lines.Length, NodeType.Float); } pcharRotation = Convert.ToSingle(ParentGraph.GetParameterValue(Id, "Rotation")); } if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Scale")) { if (ParentGraph.IsParameterValueFunction(Id, "Scale")) { FunctionGraph func = ParentGraph.GetParameterRaw(Id, "Scale").Value as FunctionGraph; func.SetVar("character", j, NodeType.Float); func.SetVar("maxCharacters", line.Length, NodeType.Float); func.SetVar("line", i, NodeType.Float); func.SetVar("maxLines", lines.Length, NodeType.Float); } pScale = ParentGraph.GetParameterValue <MVector>(Id, "Position"); } if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Position")) { if (ParentGraph.IsParameterValueFunction(Id, "Position")) { FunctionGraph func = ParentGraph.GetParameterRaw(Id, "Position").Value as FunctionGraph; func.SetVar("character", j, NodeType.Float); func.SetVar("maxCharacters", line.Length, NodeType.Float); func.SetVar("line", i, NodeType.Float); func.SetVar("maxLines", lines.Length, NodeType.Float); } pPos = ParentGraph.GetParameterValue <MVector>(Id, "Position"); } CharacterTransform ct = new CharacterTransform(pcharRotation * (float)(Math.PI / 180.0f), pPos, pScale); transforms.Add(ct); //for these two alignments we need to calculate the //actual full line width first before we do final //positing and rendering //to apply the proper adjustment //for right alignment all we need is the total //for center we need the halfway point if (palignment == TextAlignment.Center || palignment == TextAlignment.Right) { if (map.TryGetValue(ch, out data)) { alignmentAdjustment += data.size.X + pspacing; } } } if (palignment == TextAlignment.Center) { alignmentAdjustment *= 0.5f; } adjustments.Add(alignmentAdjustment); } }