- Home /
Facing problem with my character
Can any one help me with this problem
as when i apply this script to my character then my character goes through walls and other objects and there is no collisions ...So how can i fix this? 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);
}
}
}
Answer by FM-Productions · May 02, 2017 at 02:50 PM
Hey, could it be that you don't use the components required for physcial based collisions? Collisions are not handled by default from Unity, there are some Components your gameObjects have to use. If you are making a 3D game you should attach a Rigidbody and a Collider component to your character gameObject. If you are making a 2D game, it should be Rigidbody2D and a Collider2D component.
Here is tutorial example I quickly looked up, I think it should cover the basics (and also more advanced aspects) of collisions: http://www.binpress.com/tutorial/unity-3d-collisions-basics/114
Your answer
Follow this Question
Related Questions
How do I make animation transitions a one-way street? 1 Answer
The parts of my character disappear when i use the animation 0 Answers
How play an animation through collision (2D Game)? 2 Answers
Export Animations From Unity3D into Blender? 1 Answer
Unity 5: No collision with other objects after an animation? 0 Answers