• 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 kalti_mar · May 02, 2017 at 05:56 AM · unity 5collisiontransformcharactercontroller

my character is going through walls and other objects

i have have used a character from Mixamo with animations and for the movement i have used transform.translate which is making the object move but my object is moving through walls and other objects. My code is here .. help me out that how can i bring in collisions.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class galcontrols : MonoBehaviour { static Animator anim; public float speed = 10F; public float rotationSpeed = 100.0F;

 // Use this for initialization
 void Start () {
     anim = GetComponent<Animator>();
 }
 
 // Update is called once per frame
 void Update () {
     float translation = Input.GetAxis("Vertical") * speed;
     float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
     translation *= Time.deltaTime;
     rotation *= Time.deltaTime;
     transform.Translate(0, 0, translation);
     transform.Rotate(0, rotation, 0);
     if(Input.GetButtonDown("Jump"))
     {
         anim.SetTrigger("isJumping");
     }
     if(translation!=0)
     {
         anim.SetBool("isRunning",true);
         anim.SetBool("idle", false);

     }
     else
     {
         anim.SetBool("isRunning", false);
         anim.SetBool("idle", true);
     }
 }

}

Comment
Add comment · Show 1
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 EdwinChua · May 02, 2017 at 06:16 AM 0
Share

See http://answers.unity3d.com/questions/187684/moving-object-with-transformposition-ignore-other.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aditya · May 02, 2017 at 06:49 AM

To make physics effect your gameobjects you need to use rigidbody and if your are moving a gameobject with rigidbody attached you need to use MovePosition method of rigidbody class ... Attach a rigidbody to your character (if not already attached) and then take reference of this rigidbody in your code and move it using MovePosition

 public Rigidbody char_RB;
 
 void FixedUpdate(){
     if(Input.GetAxis("Vertical")){
         char_RB.MovePosition(char_RB.gameObject.transform.forward * speed);
     }
 }

Important : Always use FixedUpdate whenever dealing with physics

Comment
Add comment · Show 2 · 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 FM-Productions · May 02, 2017 at 07:51 PM 0
Share

One addition to this answer, also use a Collider component on your gameObject. The combination of Rigidbody and a collider component (such as CapsuleCollider) should get your gameObject to react to Physics. If you want to avoid going through walls etc., you also have to make sure that the collider on your Character has "isTrigger" set to false. And you also have to add Collider Components to the walls, although you do not need to add a Rigidbody to the walls, since they are static objects and should not be moved by the Unity engine.

avatar image toddisarockstar · May 03, 2017 at 03:11 AM 1
Share

$$anonymous$$ovePosition does consider the physics engine. but it assigns the position like a teleport effect. so it will move things inside another collider. in his case it would probobly cause a bounce back or shake when pressing against another collider. for general smooth movement he pry wants to apply velocity ins$$anonymous$$d like this:

 gameObject.rigidbody.velocity=new Vector3(0, 0, translation);
 
 
 

avatar image
0

Answer by infinuscerro · Mar 08, 2019 at 02:13 PM

@kalti_mar I have same problem, the object through wall/object/cube. The problem solved after I reinstall the Unity software.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer

Character Controller meets Rigidbody 1 Answer

OnCollisionEnter the Enemy Detect Collision but health damage not working but on OnTriggerEnter the health is reducing on punch but collision is not detecting 1 Answer

Collision CharacterController vs CharacterController 2 Answers

NPCs fall through hills in terrain 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