Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by SammyPeer · Mar 08, 2016 at 09:06 AM · camera rotateeuleranglesboxcollidervector3.angle

Using a camera as a child on box collider with MouseLookPlus, which way is up with euler angles?

I am attempting to make a first person character controller that can look with the mouse and jump to walls or ceilings then change the orientation so the walls or ceiling become the floor, like a person with magnetic boots in zero gravity. I have used the answer in the following script to make this work but am having difficulty adapting it to work with MouseLookPlus. It all seems to work except the angle that I get for my Raycast appears to travel up instead of directly where the camera is looking. The following is the code that I am using to get the character to jump to the wall (or ceiling).

 function Update() {
     // Jumping, ToWall or ordinary jump
     if (jumping) return; // Don't do update while moving to a wall
     var rb = GetComponent.<Rigidbody>();
     var camArray : Camera[] = GetComponentsInChildren.<Camera>();
     var cam : Camera = camArray[0];
     var ray : Ray;
     var hit : RaycastHit;
     var viewAngle : Vector3;
     viewAngle = Vector3(cam.transform.localEulerAngles.x, rb.transform.localEulerAngles.y, rb.transform.localEulerAngles.z);
     if (Input.GetButtonDown("Jump")) { // If 'jump' pressed do raycast
         ray = Ray(transform.position, viewAngle);
         if (Physics.Raycast(ray, hit, jumpRange)) {
             JumpToWall(hit.point, hit.normal); // Then jump to wall
         }
         else if (isGrounded) {
             rb.velocity += jumpSpeed * myNormal; // Or normal jump
         }
     }

And the following code is the processing of the jump itself:

 function JumpToWall(point : Vector3, normal : Vector3) {
     jumping = true; // Character is jumping
     var rb = GetComponent.<Rigidbody>();
     rb.isKinematic = true; // Turn physics off while jumping
     myNormal = normal;
     var camArray : Camera[] = GetComponentsInChildren.<Camera>();
     var cam : Camera = camArray[0];
     var viewAngle = Vector3(cam.transform.localEulerAngles.x, rb.transform.localEulerAngles.y, rb.transform.localEulerAngles.z);
     var orgPos = transform.position;
     var orgRot = Quaternion.Euler(viewAngle);
     var dstPos = point + normal * (distGround + 0.5); //jumps to 0.5 above wall
     var myForward = rb.transform.forward;
     var dstRot = Quaternion.LookRotation(myForward, normal);
     for (var t : float = 0.0; t < 1.0; ) {
         t += Time.deltaTime;
         transform.position = Vector3.Lerp(orgPos, dstPos, t);
         transform.rotation = Quaternion.Slerp(orgRot, dstRot, t);
         yield;
     }
     myNormal = normal; // update normal
     rb.isKinematic = false; //turn physics back on
     jumping = false; // jump has concluded
 }

Any assistance would be greatly appreciated, thank you in advance.

Comment
Add comment · Show 2
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 Owen-Reynolds · Mar 08, 2016 at 03:33 PM 0
Share

The code computing ViewAngle doesn't look even close to correct, for the input to a raycast. You should be able to search for the direction a camera is facing, and how to make a ray.

avatar image SammyPeer Owen-Reynolds · Mar 09, 2016 at 12:39 AM 0
Share

Thanks for pointing me in the right direction Owen, I found 'ViewportPointToRay' in Camera and it works a treat. Now to iron out a few more bugs and I should have it working.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate object A based on camera y rotation if angle is grather or less then 0 Answers

Problem rotating camera on negative z axis 1 Answer

Using DampSmooth in EulerAngle is affecting the Position.Z value of the gameObject. 0 Answers

camera doesn't work after reloading the scene 0 Answers

Why doesn't my camera work?,Why does my mouse keep going up? 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