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 TRiToNDREyJA · Jan 27, 2013 at 10:41 PM · terrainnormalsslopealign

how can I align player with slope normals(no rigidbody)

i really need to find out how to do this, ive read about raycasts and looked through answers, but none of them work. my character either rotated randomly or teleported. can someone make me a script?

Here is my char controller:

 public var walkSpeed : float = 1.0; private var gravity = 60; private var moveDirection : Vector3 = Vector3.zero; private var charController : CharacterController; //private var power : float = 4.0;
 public var JumpSpeed : float; 
 public var motor : CharacterMotor;
 public var acc : float;
 public var maxspeed : float;
 var underwater : boolean = false;
 public var motor2 : CharacterMotorJumping;
 function Start() { charController = GetComponent(CharacterController); animation.wrapMode = animation.wrapMode.Loop;
 targetNormal = transform.up;
  }
 public var pad : float = 0.0f;
 var jumpingFromPad : boolean = false;
 var canJumpFromPad : boolean = true;
 public var streak : GameObject; // player direction in X-Z space;
 public var energy : float;
 public var isGrounded : boolean = false;
 //Make raycast direction down
 public var homing : homingattack;
 private var vertVel: float = 0; // vertical velocity 
 function Awake () {
     motor = GetComponent(CharacterMotor);
 }
 function Update () {
     if(Input.GetKey("e") ) {      
          animation.CrossFade("Jump");
         }
     if(!isGrounded)
     {
         homing.canhome = true;
     }
     if (jumpingFromPad)
     {
         animation.CrossFade("Up");
     }
     if (canJumpFromPad && jumpingFromPad)
     {
             
             
             pad += Time.deltaTime;
             vertVel = 100;
 
     }
 
     if (pad >= 1.5f && jumpingFromPad)
             {
             pad = 0;
             jumpingFromPad = false;
             homing.canhome = true;
             }
     
     var distToGround: float;
     isGrounded = Physics.Raycast(transform.position, -Vector3.up, distToGround + 1.5);
     if(Input.GetKey("left shift")&&  isGrounded) {
     energy = 3;
     }
          if(Input.GetKey("e") ) {      
          animation.CrossFade("Jump");         
          animation["Jump"].speed = 20; 
          }
      
     if(Input.GetAxis("Vertical") > 0.1 && isGrounded) {
     if (charController.isGrounded)
     {
          if(Input.GetKey("left shift")) {
               animation["Run"].speed = 90;
          }
 
          else {
               animation.CrossFade("Run");
               animation["Run"].speed = 1;
          }
     }
     }
     else
         {
         if (charController.isGrounded == false)
             {    
                 if(Input.GetAxis("Vertical"))
                 {
                 animation.CrossFade("Fall2");
                 }
                 if(Input.GetKey("e"))
                 {
                 }
                 else
                 {
                 animation.CrossFade("Fall2");
                 }
         }
         else {
          if (walkSpeed >0)
          {
              walkSpeed -= (walkSpeed/3);
          }
              if (walkSpeed <1)
              {
              animation.CrossFade("Idle");
              }
         }
         }    
 
     // Create an animation cycle for when the character is turning on the spot
     if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical"))
     {
         //animation.CrossFade("walk");
     }
 
 
 
     transform.eulerAngles.y += (Input.GetAxis("Horizontal") * 5);
 
     // Calculate the movement direction (forward motion)
     // read the controls outside the if:
     
     if (isGrounded) { // if it's grounded...
         if (Input.GetKey ("e")) { // and Jump is pressed...
             vertVel = 65; // vertical velocity = jumpSpeed
             homing.canhome = true;
             isGrounded = false;
         }
     }
     vertVel -= gravity * Time.deltaTime; // apply gravity to the vertical velocity
     moveDirection.y = vertVel; // combine move direction with vertical velocity
     moveDirection = Vector3(0, vertVel, walkSpeed);
     moveDirection = transform.TransformDirection(moveDirection);
     charController.Move(moveDirection * Time.deltaTime); // and Move
 
     
 }
 
 //this is my movement control script to switch the animations..
 
 
 
 
 
 function FixedUpdate () { if(Input.GetAxis("Vertical") > .1) {
 
     streak.particleEmitter.minEnergy = energy;
     streak.particleEmitter.maxEnergy = energy;
         if(Input.GetKey("left shift") &&  isGrounded )
         {
 
             animation.CrossFade("Run");
             animation["Run"].speed = 20;
             walkSpeed = 200;
             energy = 3;
         }
         else
         {
 
             animation["Run"].speed = 1;
             animation.CrossFade("Run");
             if (walkSpeed <= maxspeed && !underwater)
             {         
             walkSpeed += (acc);
             }         
 
             else if (underwater && walkSpeed <= (maxspeed/12))
             {
             walkSpeed += (acc/5);
             }
             
             else
             {
             if (underwater)
             {
             walkSpeed = (maxspeed/12);
             }
             else
             {
             walkSpeed = maxspeed;
             }
             
             energy = 0;
         }  
         if(Input.GetKey("e") ) {      
          animation.CrossFade("Jump");
         }
 
 
     }
     
     if(Input.GetAxis("Vertical") < -.1 &&  isGrounded )
     {
 
         animation["Run"].speed = -1;
         animation.CrossFade("Run");
         walkSpeed = 5;
     }
     if(Input.GetKey("e") ) {      
          animation.CrossFade("Jump");
          }
 
 
     
     // Create an animation cycle for when the character is turning on the spot
 }
 }
 
 
 function OnTriggerEnter(other : Collider)
 {
     if (other.tag == "jumpPad")
     {
         print ( "jumpPad reached" );
         jumpingFromPad = true;
     }
     if (other.tag == "water") {
     underwater = true;
     }
 }
 
 function OnTriggerExit ( other : Collider) {
     if (other.tag == "water") {
     underwater = false;
     }
     
 }
Comment
Add comment · Show 4
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 TRiToNDREyJA · Jan 27, 2013 at 10:25 PM 0
Share

ignore the code // comments.

avatar image Golan2781 · Jan 27, 2013 at 10:48 PM 0
Share

Could you make that question a bit more precise? It's a tad... unpractical to try and figure out where in over 200 lines of code a relevant situation and possible bug are.

avatar image TRiToNDREyJA · Jan 27, 2013 at 11:11 PM 0
Share

i am making a sonic style game. my terrain has hills and rough terrain. i want the character to say for example, rotate 45 degrees if hes walking up a 45-degree slope?. i need a script for this

avatar image TRiToNDREyJA · Jan 27, 2013 at 11:11 PM 0
Share

the code doesnt matter much. i just need to see if the jumping around is caused by the script

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

10 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

Related Questions

Align plane to normal but keep Y-axis intact 1 Answer

Using bump maps on a terrain on mobile platforms. 0 Answers

How to determine what points on terrain can be seen from a certain point? 1 Answer

Bound the gameobject from the ground 1 Answer

Set Terrain Normals 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