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 jamesdude353 · Feb 03, 2013 at 09:39 AM · cameracharacter controller

How to make my script better.

I need to make my character able to jump. I also need to make it so when he moves so he can have the camera follow him at all times. Kinda like skyrim move not like a board game type of move. what happens is he follows the keys w,a,s and d but it would make the key you pressed be forward and you would have to use mouse look to turn the mouse to the forward possition. Can someone edit my script to what will make this work. Heres my script

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class PlayerController : MonoBehaviour { public float movespeed=4; public float Damage=60; public Transform Cam; public float CamHeight=10; public float CamHeightPushback=5; public AnimationClip Run; public AnimationClip Idle; public AnimationClip Attack; public AnimationClip die; public float AttackSpeed=0.7f; private bool kill; public bool dead; private bool playd; private float atime; private bool dealdamage; public int TotalAICount; public bool YouWon; private bool w;

 public Vector3 For;
 public List KillList;
 
 // Use this for initialization
 void Start () {
     if(Cam)Cam.parent=null;
     
     w=true;
     playd=true;
 
 }
 
 // Update is called once per frame
 void Update () {
     //Victory
     if(w){
     if(TotalAICount<=0){
             YouWon=true;
         w=false;
         }
     }
     
     
     Health php=(Health)GetComponent("Health");
     if(php){
     if(php.CurrentHealth<=0)dead=true;
     }
     
     //DEATH
     if(dead){
         if(playd){
         animation.CrossFade( die.name, 0.15f);    
         }
         playd=false;
         
     }
     else{
     
     For.y=270;
     //CAMERA POSITION
     Vector3 ch=transform.position;
     ch.y=transform.position.y+CamHeight;
     ch.x=transform.position.x+CamHeightPushback;
     
     Cam.transform.position=ch;
     if(Input.GetKeyUp(KeyCode.Mouse1)){
         dealdamage=true;
     kill=true;    
     }
     
         //LETS DO SOME KILLIN!
     if(kill){
         atime+=Time.deltaTime;
         animation[Attack.name].speed = animation[Attack.name].length / AttackSpeed;
     animation.CrossFade( Attack.name, 0.15f);
         
         if(atime>=AttackSpeed*0.35f&atime<=AttackSpeed*0.48f){
         if(KillList.Count>0&dealdamage){
             int    ls=KillList.Count;
             for (int i = 0; i < ls; i++){
                 Health hp=(Health)KillList[i].transform.GetComponent("Health");
                         
                     hp.CurrentHealth=hp.CurrentHealth-Damage;
                         if(hp.Dead){}
                         else if(hp.CurrentHealth<=0)TotalAICount=TotalAICount-1;
                 }
                 dealdamage=false;
             }
         }
         
         if(atime>=AttackSpeed){
             kill=false;
             atime=0;
         }
     }
     else{
             //RUN ANIMATION IF ANY ARROW KEYS ARE PRESSED
     if(Input.GetKey(KeyCode.W)|Input.GetKey(KeyCode.S)|Input.GetKey(KeyCode.D)|Input.GetKey(KeyCode.A)){
 
             animation.CrossFade( Run.name, 0.15f);    
     }
     else{
     animation.CrossFade( Idle.name, 0.15f);        
     }
     }
     //MOVEMENT
 if(Input.GetKey(KeyCode.W)){
         transform.position += transform.forward * +movespeed * Time.deltaTime;
 Cam.transform.position += transform.forward * +(movespeed) * Time.deltaTime;
         transform.rotation=Quaternion.Euler(0, -90, 0);
 
     }
     else{
     
     if(Input.GetKey(KeyCode.S)){
         transform.rotation=Quaternion.Euler(0, 90, 0);
 transform.position += transform.forward * +movespeed * Time.deltaTime;
 Cam.transform.position += transform.forward * +(movespeed) * Time.deltaTime;
             
     }
     else{
     
     if(Input.GetKey(KeyCode.D)){
         transform.rotation=Quaternion.Euler(0, 0, 0);
 transform.position += transform.forward * +movespeed * Time.deltaTime;
 Cam.transform.position += transform.forward * +(movespeed) * Time.deltaTime;
     
     }
     
     
     if(Input.GetKey(KeyCode.A)){
         transform.rotation=Quaternion.Euler(0, -180, 0);
                 transform.position += transform.forward * +movespeed * Time.deltaTime;
 Cam.transform.position += transform.forward * +(movespeed) * Time.deltaTime;
     
     }
     }
     }
     }
 }
 
 void OnTriggerEnter(Collider other){
     //ADD AIS TO LIST TO INFLICT DAMAGE IF IN RANGE
     Health AI=(Health)other.transform.GetComponent("Health");
     if(AI){
     KillList.Add(other.transform);
         
     }
 }
 
 void OnTriggerExit(Collider other){
     //REMOVE FROM LIST WHEN OUT OF RANGE
     Health AI=(Health)other.transform.GetComponent("Health");
     if(AI){
     KillList.Remove(other.transform);
         
     }
 }
 void OnGUI(){
     //HEALTH BAR AND AI COUNT
     Health php=(Health)GetComponent("Health");
     if(php){
     float hpp=php.CurrentHealth;
     GUI.Button(new Rect(0, 30, 300, 26), "Health: "+hpp);
     }
     GUI.Button(new Rect(0, 60, 300, 26), "Evil Skellies Left: "+TotalAICount);
         
     //YOU WON!
     if(YouWon){
     GUI.Box(new Rect(200, 200, 330, 260), "Congratulations!  You have defeated all the Evil Skellies!");
         if(GUI.Button(new Rect(310, 400, 120, 26), "Continue Playing"))YouWon=false;
     }
     
 }
 

}

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Switching between one or more cameras in the same scene? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

camera focus on sphere 1 Answer

How can I do a smooth orthographic zoom with lerp? 2 Answers


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