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 peanutt · Feb 23, 2014 at 02:34 PM · charactercontrollertranslate

Forward or Reverse Character Position Skateboard Game

Esentially i want to be able to come back down the ramp in either reverse or forward position and still be able to perform my maneuvers. As it sits my character translates to a forward position each time.( my code says to do this) Any tips on what i can or what i should be looking at ? I cant work out what i should be doing.

Web build of the game so far , press space to move x,c,v,b do moves while in air....UP and Down arrows move across the ramp but in air they rotate as well.

http://home.iprimus.com.au/peanutt/Skate/Completewebbuild.html

 var horizontal = Input.GetAxis ("Horizontal");
     horizontal += -Input.acceleration.y * accelerometerScale;
     if (vertical)
     {
         var toRotate = horizontal * rotateSpeed * inAirRotateScale * Time.deltaTime;
         vertRotation += Mathf.Abs(toRotate);
         skater.Rotate(0, toRotate, 0);
     }
     //else
         //trans.Rotate(0, horizontal * rotateSpeed * Time.deltaTime, 0);
 
     //transform.Rotate(0, Input.GetAxis("Vertical") * RotationSpeed * Time.deltaTime, 0); 
     
 
     
     
        var moveDirection =  trans.forward * speed;    
     var upright = Vector3.Dot(Vector3.up, trans.forward);
     
     // We have to fake gravity when the character is vertical, since the CharacterController doesn't rotate
     moveDirection += Vector3.Lerp(Physics.gravity, Mathf.Sign(upright) * -trans.forward * Physics.gravity.magnitude, 
                         Mathf.Clamp01(Mathf.Abs(upright)));             
     if (Vector3.Dot(Vector3.up, targetForward) >= 0.9
         && speed > maxSpeed * 0.6
         && !vertical)
         
         
     {
         vertical = true;
         vertRotation = 90;
         var addPoints = verticalPoints;
         trickPoints.Add(addPoints);
         trickLabel.Add("VERT! +" + addPoints);
         trickAudio.PlayOneShot(ollieSound);
         var vertOriginalRot = skater.rotation;
     
     }
     
     
     if ( vertical )
     
     {
         moveDirection = Vector3.up  * speed;
         speed -= Time.deltaTime * Physics.gravity.magnitude;
 
         
 
         if (Input.GetKeyUp(KeyCode.V) )         
         skate360();    
         
         if (Input.GetKeyUp(KeyCode.B) )         
         skater180();    
         
         if (Input.GetKeyUp(KeyCode.C) )
         Ollie();
     
         if (Input.GetKeyUp(KeyCode.X) )         
         Kickflip();    
 
     }
 
     character.Move(moveDirection * Time.deltaTime);
     
     
     if (vertical && character.isGrounded )
     
     {    
         vertical = false;        
        trans.forward = -trans.forward;
         speed *= -1;
 
         var skaterRot = Vector3.Dot(trans.forward, skater.forward);
         if (Mathf.Abs(skaterRot) < oneEightyThreshold)
             Fall();
         else if (vertRotation > 180.0 * oneEightyThreshold)
         {
             var multiplier = Mathf.Round(vertRotation / 180.0);
         
             // Player successfully rotated around
             addPoints = oneEightyPoints * multiplier;
             trickPoints.Add(addPoints);
             trickLabel.Add(String.Format("{0}! +{1}", 180 * multiplier, addPoints));
             
         }
     
     //skater.forward = trans.forward;    
     }
                                                                                                                             
 var ray = new Ray(trans.position + Vector3.up, -Vector3.up);
 var hit : RaycastHit; 
 
     if (Physics.Raycast(ray, hit, 3, raycastMask))
     {
 
         targetRight = Vector3.Cross(hit.normal, trans.forward);
         targetForward = Vector3.Cross(targetRight, hit.normal);
         targetBack = Vector3.Cross(targetLeft, hit.normal);
         targetLeft = Vector3.Cross(hit.normal, -transform.forward);
 print ("There is something in front of the object!");
 print("We are grounded");
      //targetForward.transform.rotation = Quaternion.Slerp(transform.rotation,targetRot, Time.deltaTime * 1);
     //transform.Rotate(0.0f, 0.0f, delta_degree).
 // direction = transform.up;
     if (character.isGrounded )
      targetRot = Quaternion.LookRotation(targetForward, hit.normal);
 }
 
     Debug.DrawRay(trans.position, targetRight * 10, Color.green);
     Debug.DrawRay(trans.position, targetForward * 10, Color.white);
     Debug.DrawRay(trans.position, targetLeft * 10, Color.red);
     Debug.DrawRay(trans.position, targetBack * 10, Color.blue);
     
     trans.rotation = Quaternion.Slerp(trans.rotation, targetRot, Time.deltaTime * 4.6);
 
         if ( character.isGrounded )    
     
     {    
         // Stop the character when he has slowed down enough
         if (Mathf.Abs( speed ) <= 0.3)
         {
             speed = 0;
             anim.Play("standing_board_up");
             loopAudio.Stop();
         }
         else
             // Simple friction to slow character down    
             speed -= decayRate * Time.deltaTime * speed;                
     }    
     
     if (currentInstruction == InstructionOrder.DONE)
         showInstructions = false;        
 }
 

 
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 dev01 · Mar 06, 2015 at 03:44 PM 0
Share

I think its about on collision or landing getting the new vect9r3 and assigning that as your new move direction.

I was wondering if this works in the new unity5 personal edition? I was doing the same kind of project and upgraded and now I can't even get into the air because I get stuck non the ramp. Its like the transform for gravity is messed up

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

C# FP_Camera not following Character Controller 0 Answers

Why is my character's y axis randomly changing? 1 Answer

How to detect on which side my character controller was hit? 1 Answer

help pls beginner, keyboard script 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