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 ani2020.bhandari · Dec 19, 2012 at 03:40 PM · gamejumprunside

Help Me with My Script Pls??????

  • List item

So, I am Trying To make A temple run game and i am not able to jump or make it go side ways Please Help following is my Script

     public var speed = 10.0f; 
     var jumpSpeed = 20.0f;
  var gravity =20.0f;
  private var moveDirection = Vector3.zero;
  private var grounded :
  boolean = false; var coin = 0; var
      coinText = "coin: 0";
     var sideSpeed =12;
      
      function Start(){ // Set all
      animations to loop   
      animation.wrapMode = WrapMode.Loop;   
      // except shooting   
      animation["side"].wrapMode =
      WrapMode.Once;   
      animation["side"].layer = 1;   
      animation["jump"].wrapMode =
      WrapMode.Once;   
      animation["jump"].layer = 2;
      animation.Stop(); }
      
      
      function FixedUpdate() {
          if (grounded) {
          
          if (Mathf.Abs(Input.GetAxis("Vertical"))     <= 0.1){
             animation.CrossFade("run");
              
              }
              
           } 
                
               // We are grounded, so recalculate movedirection directly from axes
          moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
              moveDirection = transform.TransformDirection(moveDirection);
              moveDirection *= speed;
                if(Input.GetButtonDown("side")){
              animation.CrossFade("side");
              }
              
                if(Input.GetButtonDown("Jump")) {
      moveDirection.y = jumpSpeed; }
       
       
          if(Input.GetButtonDown("Jump")) {
       
          animation.CrossFade("jump");
          }
      
      // Apply gravity moveDirection.y -=
      gravity * Time.deltaTime;
      
      // Move the controller 
 `    `var controller
      : CharacterController =
      GetComponent(CharacterController); var
      flags = controller.Move(moveDirection
      * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 `` }
      
      @script
      RequireComponent(CharacterController)
      
      
      function Update()  {
      transform.position +=
      transform.forward * speed *
      Time.deltaTime; 
          speed += 2.0 * Time.deltaTime;    }
      
      
       function OnTriggerEnter( other :     Collider ) {
          Debug.Log("OnTriggerEnter() was called");
          if (other.tag == "Gold") {
              Debug.Log("Other object is a coin");
             coin += 1;
              coinText = "Score: " + coin;
              Debug.Log("Score is now " + coin);
              Destroy(other.gameObject);
          }
          if (other.tag == "Blue") {
              Debug.Log("Other object is a coin");
              coin += 2;
              coinText = "Score: " + coin;
              Debug.Log("Score is now " + coin);
              Destroy(other.gameObject);
          }
          if (other.tag == "Red") {
              Debug.Log("Other object is a coin");
              coin += 3;
              coinText = "Score: " + coin;
              Debug.Log("Score is now " + coin);
              Destroy(other.gameObject);
          } }
      
      function OnGUI () {
           GUI.Label (Rect (10, 10, 100, 20), coinText);
  }






Comment
Add comment · Show 1
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
avatar image cagezero · Dec 19, 2012 at 05:40 PM 0
Share

Please format your code using code tags.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JaydenM1997111 · Dec 20, 2012 at 06:48 PM

         public var Player: GameObject;
         public var MoveOnX : float;
         public var MoveOnY : float;
         public var jumpHeight : float = 20;
         public var MoveSpeed : float = 2;
         public var DefaultPos : Vector3;
         public var NewPos : Vector3;
         
         function Start(){
             DefaultPos = transform.localposition; 
         }
         function Update () {
             MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
                MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
                NewPos = new Vector3 (DefaultPos.x+MoveOnX, DefaultPos.y+MoveOnY, DefaultPos.z);
                Player.transform.localPosition = Vector3.Lerp(Player.transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);
             
             if( Input.GetButtonDown("Jump")){
                  NewPos = new Vector3 (DefaultPos.x, DefaultPos.y+jumpHeight, DefaultPos.z);
                 Player.transform.localPosition = Vector3.Lerp(Player.transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);
             }
         }

This code is to make your player jump and then slide back to its position :)

By doing this you create the jump with ease, just edit a few values :)

hope it works

Comment
Add comment · Show 1 · Share
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
avatar image ani2020.bhandari · Dec 21, 2012 at 07:44 AM 0
Share

Not Working But Thanx For trying And I Don't want to use my mouse for movement

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

11 People are following this question.

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

Related Questions

How to make smooth jump? 1 Answer

Play Audio While Button is Held Down 1 Answer

Trigger Pause Screen when escape key is pressed? 0 Answers

How do you run a exe from code 1 Answer

Full controller support - Jump, Run animation problem. 3D Side scroller. Smash Bros style. 0 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