- Home /
Question by
xPisi · Jun 14, 2015 at 02:02 PM ·
c#collisioncollision detection
Problem on collision between object
When I move the player (in this case is the light-blue cube ) and i go to the green big block , the player go inside for half into the green block.
if u want check my code for player control
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
public float Velocita = 5;
Quaternion rotation;
public GameObject Spawn;
void Awake()
{
rotation = transform.rotation;
}
void LateUpdate()
{
transform.rotation = rotation;
}
// Update is called once per frame
void Update ()
{
/* x | y | z */
Vector3 Up_Right = new Vector3(0.2f , 0.0f , 0.0f);
Vector3 Up_Left = new Vector3(0.0f , 0.0f , 0.2f);
Vector3 Down_Right = new Vector3( 0.0f , 0.0f , -0.2f);
Vector3 Down_Left = new Vector3(-0.2f , 0.0f , 0.0f);
Vector3 Resapawn = new Vector3(-0.2f , 0.0f , 0.0f);
if( Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
gameObject.transform.Translate(Vector3 Down_Left);
}
if( Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
gameObject.transform.Translate(Up_Right);
}
if( Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
gameObject.transform.Translate(Up_Left);
}
if( Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
{
gameObject.transform.Translate(Down_Right);
}
if (Input.GetKeyDown (KeyCode.R))
{
gameObject.transform.position = Spawn.transform.position;
}
}
}
the-screen.png
(81.3 kB)
Comment
Your answer
Follow this Question
Related Questions
Resize Array Based on Value 2 Answers
Multiple Cars not working 1 Answer
if statement not working when detecting collision between two prefabs 1 Answer
Could some one help me with this script... 5 Answers
Why the npc character walking strange when using a Rigidbody and Is Kinematic on enabled ? 1 Answer