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 Seyren · Sep 18, 2015 at 04:02 PM · collisionvector3collision detectionreflect

Rotating a character with character controller when colliding a wall.

This is kind of hard to explain, but i want to code a walljump with a character controller and i want to do this in two steps. For example when i press the Jump button when near a wall, i want the character to have the Same orientation than the wall and then jump out.

Here's what i've done.

     void OnControllerColliderHit(ControllerColliderHit hit)
     {
         if ((Input.GetButtonDown("Jump")) && (_controller.collisionFlags & CollisionFlags.CollidedSides) != 0 && !_grounded)
         {
             _hitNormal = hit.normal;                                //Normal of the hit
             _wjtimer = 0.0f;                                        //Timer the character is on the wall
             _preWJ = true;                                          //Boolean that is pre-walljumping
             _walljump = Vector3.Reflect(_velocity, _hitNormal);     //Direction the character will jump out after being for 0.5 seconds
             _wjwallvector = _hitNormal;        
 
             _staticRotation.eulerAngles = _wjwallvector;            //Rotation the character will be facing in the wall
             _followcamera = false;                                  //The character will stop following the camera
         }
     }

Basically _wjwallvector is the vector the character will be facing for 0.5 seconds before walljumping, which should be facing the wall that the character was facing when i pressed space.

_walljump is the Direction the character will be pushed out the wall after being in the wall for 0.5 seconds.

Basically my issue here is that i get both vectors WRONG, they always give odd results

For example the _wjwallvector is always facing the same direction no matter what wall i jump to. and the _walljump vector makes me jump to a odd place too, in short none of them work properly.

TL;DR: I want to get two vectors: _wjwallvector: Make the character face the wall i jumped to. _walljump: Make the character jump to the opposite angle i jumped to (Basically a reflected vector).

Is there any way i could get the right values of these two rotations? i would really appreciate it since i'm stuck in this issue and i don't find a way out

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bburtson09 · Sep 18, 2015 at 11:22 PM

I am having a hard time following but, instead of using the walls position maybe... if our conditionals are satisfied we can consider using a vector3.addforce relative the players position and rotation.

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 Seyren · Sep 19, 2015 at 01:58 AM 0
Share

The issue is that the Character controller has nothing such as .AddForce

Basically what i'm trying to explain is that I need two vectors, one that makes the character Face the wall is colliding when i pressed space (For example, if the wall is in my left and i press space while colliding the wall, the character will look left.

The other one is a reflected vector, which is pretty much what this arrow does in the picture.

http://i.stack.imgur.com/QGuay.png

The problem i have is that i don't know how to get these values.

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

31 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 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 detect the angle of collision on disc object ? 0 Answers

Changing light color between players when they collide (BOLT) 0 Answers

Why Character is going through the floor. 0 Answers

Properly attach to a GameObject after collision? 0 Answers

Collisions in Editor Test Runner 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