本文整理汇总了C#中CharacterController.Move方法的典型用法代码示例。如果您正苦于以下问题:C# CharacterController.Move方法的具体用法?C# CharacterController.Move怎么用?C# CharacterController.Move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharacterController
的用法示例。
在下文中一共展示了CharacterController.Move方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
void Update()
{
controller = GetComponent<CharacterController>();
speed = walkspeed;
if (controller.isGrounded)
{
if(Input.GetKey("right cmd"))
{
speed = runspeed;
}
moveDirection = new Vector2(0,Input.GetAxis("Vertical"));
//moveDirection = new Vector2(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
float turn = Input.GetAxis("Horizontal");
moveDirection *= speed;
//transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
transform.Rotate(0,0,turn * turnSpeed * Time.deltaTime);
//Vector3 forward = transform.TransformDirection(Vector3.forward);
//curSpeed = speed * Input.GetAxis("Vertical");
//if (Input.GetButton("Jump"))
//{
// moveDirection.y = jumpSpeed;
//}
}
//controller.SimpleMove(moveDirection * curSpeed);
//moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
//controller.SimpleMove(moveDirection*Time.deltaTime * 10000);
}
示例2: Update
// Update is called once per frame
void Update()
{
//rotateLeftRight = Input.GetAxis ("Rotate");
forward = Input.GetAxis ("Vertical") * moveSpeed;
LRward = Input.GetAxis ("Horizontal") * moveSpeed;
mouseLR = Input.GetAxis ("Mouse X") * mouseSensitivity;
mouseUD = Input.GetAxis ("Mouse Y") * mouseSensitivity;
characterController = GetComponent<CharacterController>();
if( verticalVelocity > -1 )
verticalVelocity += Physics.gravity.y * Time.deltaTime / 0.8f;
Debug.Log (verticalVelocity);
if ( Input.GetButtonDown("Jump") && characterController.isGrounded) {
Debug.Log("jump!");
verticalVelocity = jumpSpeed;
}
desiredUpDown -= mouseUD;
desiredLeftRight -= mouseLR;
desiredUpDown = Mathf.Clamp (desiredUpDown, -60f, 60f);
Camera.main.transform.rotation = Quaternion.Euler (desiredUpDown, -desiredLeftRight , 0);
transform.rotation = Quaternion.Euler (0, -desiredLeftRight , 0);
//transform.Rotate (0,mouseLR,0);
Vector3 speed = new Vector3 (LRward, verticalVelocity, forward); //go forward
speed = transform.TransformDirection(speed);
Debug.Log ("Speed:" + speed);
characterController.Move (speed);
}
示例3: Update
// Update is called once per frame
void Update()
{
velocity = Vector3.zero;
controller = GetComponent(
typeof(CharacterController)) as CharacterController;
// Determine if movement is desired along the
// selected axis by the user. If set, "velocity" will be an
// axis specific unit vector.
if (axis == AxisChoice.X) {
velocity.x = Input.GetAxis("Horizontal");
} else if (axis == AxisChoice.Y) {
velocity.y = Input.GetAxis("Vertical");
} else if (axis == AxisChoice.Z) {
// NOTE: Jump doesn't have a negative button
velocity.z = Input.GetAxis("Jump");
}
// Scale the unit vector
velocity = transform.TransformDirection(
velocity * maxSpeed * Time.deltaTime);
// Move the character
controller.Move(velocity);
}
示例4: FixedUpdate
void FixedUpdate()
{
Controller = GetComponent<CharacterController> ();
if (Controller.isGrounded && canMove == true) {
// We are grounded, so recalculate
// move direction directly from axes
animator.SetBool("Jump", false);
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
if (Input.GetButton("Jump"))
{
Ymove = jumpSpeed;
animator.SetBool("Jump", true);
}
else
{
Ymove = 0;
}
}
Ymove -= Gravity * Time.deltaTime;
moveDirection.y = Ymove;
Controller.Move(moveDirection * Time.deltaTime);
}
示例5: FixedUpdate
//Update is called once per frame
void FixedUpdate()
{
//Defines how player movement works
controller = GetComponent<CharacterController>();
movement.x = 0;
if(Input.GetKey(moveLeft))
movement.x = -moveSpeed;
else if(Input.GetKey(moveRight))
movement.x = moveSpeed;
if(controller.isGrounded){
vertSpeed = 0.0f;
if(Input.GetKey(moveJump)){
vertSpeed = jumpSpeed;
}
}
vertSpeed -= gravity*Time.deltaTime;
movement.y = vertSpeed;
controller.Move(movement * Time.deltaTime);
//End player movement
}
示例6: Update
void Update()
{
key = GetComponent<KeyboardInput> ();
controller = GetComponent<CharacterController> ();
if (controller.isGrounded && !isOnMovingPlataform) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if(key.JumpButtonPressedThisFrame)
moveDirection.y = 10.0F;
}
moveDirection.y -= 30.0F * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
}
示例7: OnActivate
/* BEGIN REGULAR POWER */
public override IEnumerator OnActivate(Hero sourceHero, Hero otherHero)
{
CreateBungieLink(otherHero, sourceHero, "SpiritLinkChain");
//Debug.Log("Activating" + this.GetType());
heroCC = otherHero.GetComponent<CharacterController>();
currentBungieTime = 0;
initialPosition = otherHero.transform.position;
Vector3 directionToBungie = GetBungieMovement(currentBungieTime, initialPosition, sourceHero.transform.position - initialPosition, durationToBungie);
heroCC.Move(directionToBungie - otherHero.transform.position);
return null;
}
示例8: FixedUpdate
// Update is called once per frame
void FixedUpdate()
{
//Defines how player movement works
controller = GetComponent<CharacterController>();
movement = Vector3.zero;
if(Input.GetKey(moveUp))
movement.z = moveSpeed;
if(Input.GetKey(moveDown))
movement.z = -moveSpeed;
if(Input.GetKey(moveLeft))
movement.x = -moveSpeed;
if(Input.GetKey(moveRight))
movement.x = moveSpeed;
controller.Move(movement * Time.deltaTime);
//End player movement
}
示例9: MoveFrame
/// <summary>
/// 캐릭터를 프레임 별로 이동 시키고 목적지까지의 거리를 넘겨줌
/// </summary>
/// <param name="cc"></param>
/// <param name="target"></param>
/// <param name="moveSpeed"></param>
/// <param name="turnSpeed"></param>
/// <returns></returns>
public static float MoveFrame(CharacterController cc,
Transform target, float moveSpeed, float turnSpeed)
{
Transform t = cc.transform;
Vector3 dir = target.position - t.position;
Vector3 dirXZ = new Vector3(dir.x, 0f, dir.z);
Vector3 targetPos = t.position + dirXZ;
Vector3 framePos = Vector3.MoveTowards(
t.position,
targetPos,
moveSpeed * Time.deltaTime);
//이동
cc.Move(framePos - t.position + Physics.gravity);
//회전도 같이 함
RotateToDir(t, target, turnSpeed);
return Vector3.Distance(framePos, targetPos);
}
示例10: Update
void Update()
{
Controller = GetComponent<CharacterController>();
var lookX = -Input.GetAxis("Mouse Y");
var lookY = Input.GetAxis("Mouse X");
Rotate(lookX, lookY);
if (Controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
Controller.Move(moveDirection * Time.deltaTime);
}
示例11: Update
private void Update()
{
// Checking for WaterDetector
if (_waterDetector == null) {
_waterDetector = GetComponent<WaterDetector>() ?? gameObject.AddComponent<WaterDetector>();
}
// If we are in the water
if (_waterDetector != null) {
_controller = GetComponent<CharacterController>();
_thirdPersonController = GetComponent<DW_ThirdPersonController>();
// If we are actually submerged to a some extent
float waterLevel = _waterDetector.GetWaterLevel(transform.position);
float min = _controller.bounds.center.y;
float max = _controller.bounds.center.y + _controller.height / 2f;
// Assume we can swim when at least half submerged into water
_isSubmerged = (min < waterLevel && max > waterLevel) || (min < waterLevel && max < waterLevel);
// Value of 1 means fully submerged, value of 0 means not submerged
float submergedCoeff = Mathf.Clamp01((waterLevel - min) / (max - min));
if (_isSubmerged) {
bool flag = Input.GetKey(SwimUpKey);
if (flag) {
_thirdPersonController.VerticalSpeed = 0f;
}
// Swimming u
if (Input.GetKey(SwimUpKey)) {
_controller.Move(Vector3.up * SwimSpeed * submergedCoeff * Time.deltaTime);
}
}
}
}
示例12: Start
void Start()
{
gameManager = GameObject.FindWithTag("GameController").GetComponent<GameManagement>();
joueur=GameObject.FindGameObjectWithTag("Player");
rand = (int)(Mathf.Round(Random.value*40)+10);
controller = GetComponent<CharacterController>();
tailleCol = GetComponent<SphereCollider> ();
vectEnnemie = changeA ();
vectEnnemie = transform.TransformDirection(vectEnnemie);
vectEnnemie *= (0.3F*speed);
vectEnnemie.y -= gravity * Time.deltaTime;
controller.Move(vectEnnemie * Time.deltaTime);
}
示例13: Update
// Update is called once per frame
void Update()
{
sprite = GetComponent<tk2dSprite>();
// it's us, lets do things legit
if(networkView.isMine)
{
actions = GetComponent<PlayerActions>();
if (canMove)
{
controller = GetComponent<CharacterController>();
moveDirection = new Vector3(0,0,-0.1f);
if (PlayerInfo.gameStarted && !actions.IsStunned() && Input.GetButton("Horizontal"))
{
moveDirection.x += Input.GetAxis("Horizontal") * speed * Time.deltaTime;
sprite.FlipX = (Input.GetAxis("Horizontal") < 0) ? true : false;
spriteFlipped = sprite.FlipX;
if (!walking) walking = true;
}
else
if (walking) walking = false;
if (controller.isGrounded)
{
gravityTotal = gravity;
isJumping = false;
jumpTotalTime = 0;
isFalling = false;
canJump = true;
upVelocity = 0;
}
else
{
isFalling = true;
}
ApplyJumping();
ApplyGravity();
// jumpPower determined by ApplyJumping()
moveDirection.y += upVelocity * Time.deltaTime;
controller.Move(moveDirection);
// tell network of new position
networkView.RPC("BroadcastPosition", RPCMode.AllBuffered, transform.position);
if (actions.IsStunned()) animationClip = "stunned";
else if (actions.IsSwinging()) animationClip = "picking";
else if (walking) animationClip = "walking";
else if (isJumping) animationClip = "jumping";
else animationClip = "standing";
anim.Play(animationClip);
networkView.RPC("BroadcastAnimation", RPCMode.AllBuffered, spriteFlipped, animationClip);
// keeps us on the correct z
Vector3 pos = transform.position;
pos.z = 0;
transform.position = pos;
}
}
else // other player
{
//update position
transform.position = position;
//update animation
sprite.FlipX = spriteFlipped;
anim.Play(animationClip);
}
}
示例14: DoActionDirect
private void DoActionDirect(Transform axisTransform, PropertiesInfluenced inlfuencedProperty, Vector3 axis, float sensibility, CharacterController charact)
{
switch (inlfuencedProperty)
{
case PropertiesInfluenced.Rotate:
axisTransform.Rotate((Vector3) ((axis * sensibility) * Time.deltaTime), Space.World);
break;
case PropertiesInfluenced.RotateLocal:
axisTransform.Rotate((Vector3) ((axis * sensibility) * Time.deltaTime), Space.Self);
break;
case PropertiesInfluenced.Translate:
if (charact != null)
{
Vector3 vector = new Vector3(axis.x, axis.y, axis.z);
vector.y = -(this.yAxisGravity + this.xAxisGravity);
charact.Move((Vector3) ((vector * sensibility) * Time.deltaTime));
break;
}
axisTransform.Translate((Vector3) ((axis * sensibility) * Time.deltaTime), Space.World);
break;
case PropertiesInfluenced.TranslateLocal:
if (charact != null)
{
Vector3 vector2 = (Vector3) (charact.transform.TransformDirection(axis) * sensibility);
vector2.y = -(this.yAxisGravity + this.xAxisGravity);
charact.Move((Vector3) (vector2 * Time.deltaTime));
break;
}
axisTransform.Translate((Vector3) ((axis * sensibility) * Time.deltaTime), Space.Self);
break;
case PropertiesInfluenced.Scale:
axisTransform.localScale += (Vector3) ((axis * sensibility) * Time.deltaTime);
break;
}
}
示例15: CoUpdate
IEnumerator CoUpdate()
{
myTrans = this.transform;
//baseYPosition = myTrans.localPosition.y;
myItems = this.GetComponent<PlayerItems>();
controller = this.GetComponent<CharacterController>();
Physics.IgnoreLayerCollision( 30, 31 );
while(true)
{
if(grabbedItem || pauseMovement)
{
//Do nothing.
}
else
{
//Useable Item
if(Input.GetKeyDown(KeyCode.Space))
{
if(currentUseableItem != null)
{
currentUseableItem.startLocation = myTrans;
currentUseableItem.Activate();
}
}
//Movement
pressedDirection = DoorLocation.None;
moveDirection = Vector3.zero;
if(Input.GetKey(KeyCode.D))
{
moveDirection += new Vector3(movementCheck, 0, 0);
pressedDirection = DoorLocation.Right;
}
if(Input.GetKey(KeyCode.A))
{
moveDirection += new Vector3(-movementCheck, 0, 0);
pressedDirection = DoorLocation.Left;
}
if(Input.GetKey(KeyCode.S))
{
moveDirection += new Vector3(0, 0, -movementCheck);
pressedDirection = DoorLocation.Down;
}
if(Input.GetKey(KeyCode.W))
{
moveDirection += new Vector3(0, 0, movementCheck);
pressedDirection = DoorLocation.Up;
}
if(moveDirection == Vector3.zero)
pressedDirection = DoorLocation.None;
preMovement = moveDirection;
moveDirection = transform.TransformDirection(moveDirection);
float tempMovementMod = 0;
if(myStats.MovementSpeed < 5)
tempMovementMod = movementSpeedModifier/1.3f;
else
tempMovementMod = movementSpeedModifier/1.5f;
moveDirection *= myStats.MovementSpeed*movementSpeedModifier;
if(canAttack)
{
//Handling Movement Animations
if(Input.GetKey(KeyCode.UpArrow))
{
lastKeyPress = KeyCode.UpArrow;
Shoot(Vector3.forward);
}
else if(Input.GetKey(KeyCode.DownArrow))
{
lastKeyPress = KeyCode.DownArrow;
Shoot(Vector3.back);
}
else if(Input.GetKey(KeyCode.LeftArrow))
{
lastKeyPress = KeyCode.LeftArrow;
Shoot(Vector3.left);
}
else if(Input.GetKey(KeyCode.RightArrow))
{
lastKeyPress = KeyCode.RightArrow;
Shoot(Vector3.right);
}
switch(lastKeyPress)
{
case KeyCode.UpArrow:
if(moveDirection.magnitude > 0.1f)
player.Play("BackWalking");
else
player.Play("BackIdle");
break;
case KeyCode.DownArrow:
if(moveDirection.magnitude > 0.1f)
//.........这里部分代码省略.........