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 D12564 · Sep 16, 2021 at 07:08 PM · collisionraycastteleportblink

Blink Ability Issues with Angles and Certain Objects

Hello everyone, I'm relatively new to using Unity and have been attempting to program a blink ability for a character. I've been trying to get it to work for 2-3 days now, but I'm pretty much stumped on what I should be doing.

Explanation: My player model is using the Character Controller system rather than Rigidbody as I first attempted to use the other system, but couldn't program basic movements so instead I switch to the Character Controller. Currently I'm using Raycasts to detect collisions to let my player know if their teleport path is obstructed. However, I need the ability to trigger as well even if there is no hit, and it must be capable of both vertical and horizontal teleportation. This works fairly well, but there are two issues. The first is that at certain angles my player falls through the ground when teleporting on no Raycast hit. I'm guessing this is due to them teleporting, but clipping into the ground causing them to fall through. The second is sometimes the teleport location isn't aligned with the forward direction as it should be. Instead they would be teleported sideways or not move at all. This only seems to occur when attempting to teleport towards a wall or slope.

I'm honestly not sure what to do, should I just try to switch back to Rigidbody? Any help would be appreciated. Also I only started out coding about three days ago so if there are significant faults in my work here please let me know.

Code:

 public class WarperAbilities : MonoBehaviour
 {
     public int uses = 5;
     public int maxUses = 5;
     public float cooldown;
     public float distance = 5f;
     public Transform cameraPlayer;
     public LayerMask layerMask;
     public CharacterController controller;
     public int blinkDelay = 5;
 
     protected float blinkCooldown;
 
     RaycastHit hit;
 
     // Start is called before the first frame update
     void Start()
     {
 
     }
 
     void Blink()
     {
         Vector3 origin = transform.position;
         Vector3 direction = cameraPlayer.transform.forward;
 
         if (Physics.Raycast(origin, direction, out hit, distance, layerMask))
         {
             Vector3 endPoint = hit.point + hit.normal * 1.5f;
             GetComponent<CharacterController>().enabled = false;
             transform.position = endPoint;
             GetComponent<CharacterController>().enabled = true;
 
             print(hit.transform.name);
         }
         else
         {
             GetComponent<CharacterController>().enabled = false;
             transform.position = cameraPlayer.transform.forward * distance + new Vector3(0f, 1f, 0f);
             GetComponent<CharacterController>().enabled = true;
         }
     }
 
     void Update()
     {
         blinkCooldown += Time.deltaTime;
 
         if (Input.GetKeyDown(KeyCode.Q) && uses >= 1)
         {
             uses -= 1;
             Blink();
         }
         else if (uses < maxUses && blinkCooldown >= blinkDelay)
         {
             blinkCooldown = 0;
             uses++;
         }
     }
 }
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

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

235 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 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 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 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 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 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 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 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

Camera collision detection. 0 Answers

Enemy not jumping using Raycast 1 Answer

Dashing through enemies, but not walls. 1 Answer

Physics2D.Raycast(localPos vs pos, Vector2.up) ? 1 Answer

Stopping player's Blink ability with Raycasts.? 1 Answer


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