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 /
This question was closed Mar 19, 2019 at 07:36 PM by hexagonius for the following reason:

The question is answered, right answer was accepted

avatar image
5
Question by TheDDestroyer12 · Jan 05, 2015 at 05:26 PM · collisioncollider

How to prevent Collider from shaking when colliding with another Collider?

Hello!

I'm creating a player controller script for my first person game, and I have a problem. When I move the player and it collides with something, it starts shaking and moves back and forth. I've read that this is because of the transform.Translate() function, so I've tried placing it in the LateUpdate() function instead of the default Update() function, to make it execute at the same time as the physics code. That makes it a bit better, but it still shakes too much. It works well with the built in CharacterController.Move(), but I want to code the controller myself, so I wonder how I can solve this. I've read one possible solution; to use multiple raycasts and check if something is blocking the player before it is being moved, but I don't really know how I can do that so that it checks "the whole area in front of the player"?

All help is appreciated!

// TheDDestroyer12

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

2 Replies

  • Sort: 
avatar image
12
Best Answer

Answer by hexagonius · Jan 05, 2015 at 05:33 PM

FixedUpdate would run your code in the same step as the physics calculation. Collision and translation never is a good idea, because it bypasses the calculations of the physics engine. Instead of translating by a certain amount, set the velocity of the object (if course it needs a rigidbody). It will make the object move by the same amount, but the collision will work fine. Do that in FixedUpdate().

Comment
Add comment · Show 3 · 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 TheDDestroyer12 · Jan 05, 2015 at 06:12 PM 0
Share

Okay, thanks! But what is LateUpdate() then?

avatar image hexagonius · Jan 05, 2015 at 07:04 PM 1
Share

Check this out: http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.LateUpdate.html

It states "LateUpdate is called after all Update functions have been called"

This especially useful for camera movement, because you usually want it to move after everything else has moved. LateUpdate makes sure of that.

avatar image TheDDestroyer12 · Jan 06, 2015 at 09:04 AM 0
Share

Okay, thanks! Now I'll move my camera rotation part of the script to the LateUpdate() method. :)

avatar image
3

Answer by bowserscastle · Apr 24, 2018 at 01:42 AM

To expand on the other answer with a code sample, you'd do something like this:

 public Vector2 movement = new Vector2();
 Rigidbody2D rb2D;

 private void Start()
 {
     rb2D = GetComponent<Rigidbody2D>();
 }

 void FixedUpdate()
 {
     GetInput();
     MoveCharacter(movement);
 }

 private void GetInput() {
     
     movement.x = Input.GetAxisRaw("Horizontal");
     movement.y = Input.GetAxisRaw("Vertical");
 }

 public void MoveCharacter(Vector2 movementVector)
 {
     movementVector.Normalize();
     // move the RigidBody2D instead of moving the Transform
     rb2D.velocity = movementVector * movementSpeed;
 }
Comment
Add comment · Show 3 · 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 potatokiller234 · Mar 18, 2019 at 08:21 PM 1
Share

@bowserscastle How would I do the same thing, if it way in 3d. As in if you move your mouse left your object moves and if you press the w key it moves in the direction you are going, without the jittering when colliding with objects. Thanks!

avatar image hexagonius potatokiller234 · Mar 19, 2019 at 07:36 PM 1
Share

please open your own question

avatar image deserdoo potatokiller234 · Nov 01, 2019 at 08:25 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class $$anonymous$$oveCharacter : $$anonymous$$onoBehaviour
 {
     public float speed;
 
     public Rigidbody rb;
     
     void Update()
     {
         float xmove = Input.GetAxis("Horizontal") * speed;
         float zmove = Input.GetAxis("Vertical") * speed;
 
         
 
         rb.velocity = new Vector3(xmove, 0, zmove);
     }
 }

Follow this Question

Answers Answers and Comments

29 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

Related Questions

Object Collision PLEASE HELP!!! 1 Answer

Very simple collision death 1 Answer

Best collision detection method? 2 Answers

How do you execute Trigger-collider collision only in one gameobject? 1 Answer

Problem with Vectrosity line colliders 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