- Home /
Rpg style movement help.
i tried to make an rpg clicktomove script:
 #pragma strict
 var smooth:int; // Determines how quickly object moves towards position
 private var targetPosition:Vector3;
 var speed = 60;
 var Flag : Transform;        
 var Enemy : Transform;
 
 
 function Update () {
 
 
 
  
  
  
  
  if (Input.GetMouseButton(0)) {
             var hit: RaycastHit;
             var ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
 if (Physics.Raycast(ray2, hit)) {
                 if(hit.transform.tag == "Enemy"){
                 Enemy = hit.transform;
                 transform.GetComponent(Player).Enemy = hit.transform;
                 }
                 else{
                 Enemy = null;
             targetPosition = hit.point;
             var targetPoint = hit.point;
             var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
             transform.rotation = targetRotation;
             }
             }
             
             }
             
  
  
  
  
 var dir:Vector3 = targetPosition - transform.position;
 var dist:float = dir.magnitude;
 var move:float = speed * Time.deltaTime;
 if(dist > move){
 transform.position += dir.normalized * move;
                 }
 else {
 transform.position = targetPosition;
 }
  
 Flag.position = targetPosition;
 if(Enemy != null){
 targetPosition = Enemy.position;
 targetRotation = Quaternion.LookRotation(Enemy.position - transform.position);
 transform.rotation = targetRotation;
 }
 transform.GetComponent(Player).targetPos = targetPosition;
 if(transform.GetComponent(Player).isAttack == false){
 transform.position += (targetPosition - transform.position).normalized * speed * Time.deltaTime;
 
 }
  
 }
but my character isn't fall down with charactercontroller and if i use rigidbody its get force and fly away. How can i fall down my character?
Answer by Joel_Ruiz_WV@yahoo.com · Oct 05, 2013 at 01:34 PM
The simplest method (how ever it's not very realistic) is to create animation called "dead" and play it when you want your character to die.
Answer by whydoidoit · Oct 05, 2013 at 01:58 PM
To move a character with a CharacterController you need to use Move or SimpleMove, rather than directly changing the transform.position.
i want to apply gravity for the player but if i add rigidbody component when its reach the end its fly away. When i add character controller the player does not fall down.
Are you moving it using one of those methods? No gravity otherwise.
yes, and i tried with rigidbody and character controller
Your example code doesn't show that though... You have gravity on in the CharacterContoller?
Your answer
 
 
             Follow this Question
Related Questions
Jumping Stopped Working. 2 Answers
gravity or others. i don't get it. what i suppose to coding it 1 Answer
Custom Gravity CharacterController 2 Answers
How to Set Gravity to a specific Object? 3 Answers
3rd person Character Control with kinect 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                