Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by waltergs · Feb 29, 2012 at 12:30 AM · mobilecharactercontrols

Mobile Game Controls like Minigore game

I need help, I wish setup my control like Minigore game.

I have Left Control for Movements and Rigth Control for rotate character, I've used "Control Setup Folder" from Stardard Assets for Mobile, it's for a top down shooter game, I have my Character in "Camera Relative Setup" Scene, My Cam is static, but when I rotate the Player with "Rigth Control", It's locally, I need rotate Globally like Minigore game, I have 4 animations for the Character: Idle, Run, Backrun and SideStep. I need rotate the Axis Movement too. Help me please! Excuse me for my English.

PlayerRelativeControl.js

@script RequireComponent( CharacterController )

// This script must be attached to a GameObject that has a CharacterController var moveJoystick : Joystick; var rotateJoystick : Joystick; var pauseJoystick : Joystick; var Ispaused = false; var cameraPivot : Transform;
// The transform used for camera rotation var Player : GameObject; var forwardSpeed : float = 4; var backwardSpeed : float = 1; var sidestepSpeed : float = 1; var jumpSpeed : float = 8; var inAirMultiplier : float = 0.25;
// Limiter for ground speed while jumping var rotationSpeed : Vector2 = Vector2( 50, 25 );
// Camera rotation speed for each axis

private var thisTransform : Transform; private var character : CharacterController; private var cameraVelocity : Vector3; private var velocity : Vector3; // Used for continuing momentum while in air

function Start() { Ispaused = false; // Cache component lookup at startup instead of doing this every frame
thisTransform = GetComponent( Transform ); character = GetComponent( CharacterController );

 // Move the character to the correct start position in the level, if one exists
 var spawn = GameObject.Find( "PlayerSpawn" );
 if ( spawn )
     thisTransform.position = spawn.transform.position;

}

function OnEndGame() { // Disable joystick when the game ends
moveJoystick.Disable(); rotateJoystick.Disable();

 // Don't allow any more control changes when the game ends
 this.enabled = false;

}

function Update() { var movement = thisTransform.TransformDirection( Vector3( moveJoystick.position.x, 0, moveJoystick.position.y ) );

 // We only want horizontal movement
 movement.y = 0;
 movement.Normalize();

 var cameraTarget = Vector3.zero;

 // Apply movement from move joystick
 var absJoyPos = Vector2( Mathf.Abs( moveJoystick.position.x ), Mathf.Abs( moveJoystick.position.y ) );    
 if ( absJoyPos.y > absJoyPos.x )
 {
     if ( moveJoystick.position.y > 0 ){
         movement *= forwardSpeed * absJoyPos.y;
         Player.animation.CrossFade("Run", 0.5);    
         }
     else
     {
         movement *= backwardSpeed * absJoyPos.y;
         cameraTarget.z = moveJoystick.position.y * 0.75;
         Player.animation.CrossFade("Backrun", 0.5);
     }
 }
 else
 {
     movement *= sidestepSpeed * absJoyPos.x;
     
     // Let's move the camera a bit, so the character isn't stuck under our thumb
     cameraTarget.x = -moveJoystick.position.x * 0.5;
     Player.animation.CrossFade("Leftrun", 0.5);
 }
 
 // Check for jump
 if ( character.isGrounded )
 {
     if ( rotateJoystick.tapCount == 2 )
     {
         // Apply the current movement to launch velocity        
         velocity = character.velocity;
         velocity.y = jumpSpeed;            
     }
 }
 else
 {            
     // Apply gravity to our velocity to diminish it over time
     velocity.y += Physics.gravity.y * Time.deltaTime;
     
     // Move the camera back from the character when we jump
     cameraTarget.z = -jumpSpeed * 0.25;
     
     // Adjust additional movement while in-air
     movement.x *= inAirMultiplier;
     movement.z *= inAirMultiplier;
 }
     
 movement += velocity;    
 movement += Physics.gravity;
 movement *= Time.deltaTime;
 
 // Actually move the character    
 character.Move( movement );
 if (moveJoystick.IsFingerDown())
 {
     //Player.animation.CrossFade("Run", 0.5);        
             
 } else {
     Player.animation.CrossFade("Idle", 0.5);
         
 }
 
 
 if ((pauseJoystick.IsFingerDown()) && (Ispaused == false))
     
 {    Time.timeScale = 0;
     Ispaused = true;
     Time.timeScale = 0;
     
             
 } else if ((pauseJoystick.IsFingerDown()) && (Ispaused == true)){
     
     Time.timeScale = 1;    
     Ispaused = false;    
     Time.timeScale = 1;    
                 
 }
 
 
 
 
 
 
 if ( character.isGrounded )
     // Remove any persistent velocity after landing    
     velocity = Vector3.zero;
 
 // Seek camera towards target position
 var pos = cameraPivot.localPosition;
 pos.x = Mathf.SmoothDamp( pos.x, cameraTarget.x, cameraVelocity.x, 0.3 );
 pos.z = Mathf.SmoothDamp( pos.z, cameraTarget.z, cameraVelocity.z, 0.5 );
 cameraPivot.localPosition = pos;

 // Apply rotation from rotation joystick
 if ( character.isGrounded )
 {    
     
     var camRotation = rotateJoystick.position;
     camRotation.x *= rotationSpeed.x;
     camRotation.y *= rotationSpeed.y;
     camRotation *= Time.deltaTime;
     
     // Rotate the character around world-y using x-axis of joystick
     thisTransform.Rotate( 0, camRotation.x, 0, Space.World );
     
      
     // Rotate only the camera with y-axis input
     cameraPivot.Rotate( camRotation.y, 0, 0 );
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to set up controls for Mobile Device (2D Space Shooter)? 1 Answer

Porting to Mobile (Touch Controls) 2 Answers

A node in a childnode? 1 Answer

number of characters in the same scene? 0 Answers

character & objects import in different scale & animation dosent work right anymor!!!! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges