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 anwserman · Aug 08, 2012 at 05:12 PM · collisioncharactercontrollercharacter controllerwarp

My Character Controller Is Warping Randomly (/w video)

Since a picture is worth a thousand words, I uploaded a movie.

http://www.youtube.com/watch?v=E3svM38kHm4

Seconds 7-18 show desired, correct response with the character controller. Seconds 18 onwards show the incorrect response.

I did not have any issues with my code (random warping, etc.) until I added in the vehicle hit/recoil feature, but I still don't know what would be causing it. My code gets triggered in OnTriggerEnter() and then uses a CoRoutine to follow through with my code.

EDIT: In the "hitVehicle" function, it's the player that's moving - not the vehicle! It's a poorly named function with a poorly named variable on the inside that I'll be sure to correct :)

EDIT2: So, I discovered when the problem crops up. When the player gets flung (during the coroutine), if the player moves surfaces - from one collider onto another - than the problem is more likely to crop up.

Also, if I don't resume normal gameplay (e.g., leave 'hitVehicle' as active even after the coroutine is finished), the player stays in the same place. So something in my normal code is causing issues with everything... though I'm not sure what. OnTriggerEnter:

 public void OnTriggerEnter(Collider other)
      {
          //check to see if the trigger entered is a vehicle
          if (other.gameObject.layer == 15)
          {
              //rem yes it is, check to see if we're not standing on a vehicle
              if ((activePlatform == null)||(activePlatform.gameObject.layer != 15))
                   {
                      Vector3 direction;
                      direction = transform.position - other.transform.position;
                      direction.y = 0.0f;
                      StartCoroutine(HitVehicle(direction));
                   }
          }
      }

Coroutine HitVehicle:

  public IEnumerator HitVehicle(Vector3 direction)  

{ float currentTime = 0.0f; float gravity = direction.y; Vector3 hitVelocity; direction.y = 0.0f;

//set character status to hit vehicle so that nothing else (normal character control) //can resume until set to false hitVehicle = true;

while (currentTime < 1.5) { if (!LevelManagerScript.Instance.GetFrozen()) { hitVelocity = direction * Time.deltaTime;

if (character.isGrounded) { gravity = 0; } else { gravity += (Physics.gravity.y * Time.deltaTime); }

hitVelocity.y = gravity; //convert to real world coordinates transform.TransformDirection(hitVelocity); //move the character character.Move(hitVelocity); //update timer currentTime += Time.deltaTime; Debug.Log("moving");

//update active platform based on collisions if (activePlatform != null) { //get values activeGlobalPlatformPoint = transform.position; activeLocalPlatformPoint = activePlatform.InverseTransformPoint(transform.position); }

//Verify we're ontop of a platform VerifyAbovePlatform(); }

yield return null; }

//reset velocity velocity = Vector3.zero;

//set forward speed to nothing forwardSpeed = 0.0f;

//let the player get hit by the vehicle again hitVehicle = false;

//clear out last line of the log so it looks 'clear' Debug.Log(" "); }

And here's the tail beginning of my Update function.

  void  Update (){
  //leave if paused
  if (LevelManagerScript.Instance.GetFrozen())
  return;
  
  //leave function if hit by vehicle
  if (hitVehicle)
  return;
 
               ....
          }

I just implemented this last night, and I know there are some more improvements that could be made. But I don't understand where the 'warping' part comes into play? Does anyone else know what might cause this to happen?

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 DESTRUKTORR · Aug 08, 2012 at 07:07 PM 0
Share

Hmm... the only reason I could see this beco$$anonymous$$g a problem is if you had crossed "transform.position" with "transform.localPosition". Given that you didn't do that, at least not in the script you've got posted here, I can't rightly say what would cause this. It certainly isn't normal, that much is for sure.

However, it may have something to do with this:

"character.$$anonymous$$ove(carVelocity);"

If you look in the documentation for CharacterController.$$anonymous$$ove, you'll note that they use "*Time.deltaTime" to modify the rate.

Then again, it may just be something completely different, within some script that would affect the playercontroller, that you've put in. If you've got any additional information on that, it may help to get an answer.

avatar image anwserman · Aug 08, 2012 at 07:11 PM 0
Share

Hey Desktruktorr, I found some code snips for letting the player slide off of terrain and also be locked onto terrain (e.g., moving platforms). I noticed that I wasn't updating those transform points during the recoil sequence (because they weren't used at all during recoil).

Could that also be the issue? Like I said in an edit, the player moves correctly during recoil UNTIL it goes back into normal gameplay mode, where those transform points then become used as a part of movement again.

That is the only thing I can possibly think of - that if being hit on PlatformA knocks you back on to PlatformB, when the first frame of normal character movement code starts up again, it thinks you're on PlatformA still and tries to move you accordingly.

This would also explain why getting hit on a single collider works fine, it's moving between colliders that's an issue.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Controller Collision 4 Answers

2.5D platformer main character collision 1 Answer

Problem with Movement Script 0 Answers

Unity 4 to 5 Character Controller Issue 1 Answer

My Character Controller is falling through... everything... 4 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