Hi there, I am making a college project and i can’t find the solution how to fix a problem when my player object collides with the walls. he doesn’t stops, just passing through them, can any one please help me with this ? and yes, the Trigger and is Kinematic options are unchecked. Here’s my player controller code.
#pragma strict
var myRigidbody2D : Rigidbody2D;
var angle:float = 0;
private var anim : Animator;
public var speed2 : float;
public var rotationSpeed: float;
//transform
var myTrans: Transform;
//object position
var myPos: Vector2;
//object rotation
var myRot: Vector3;
function OnTriggerEnter2D(col: Collider2D)
{
if(col.gameObject.tag == "Coins")
{
GameMaster.points += 1;
Destroy(col.gameObject);
}
}
function Start ()
{
myRigidbody2D = GetComponent(Rigidbody2D);
anim = GetComponentInChildren(Animator);
myTrans = transform;
myPos = myTrans.position;
myRot = myTrans.rotation.eulerAngles;
}
function FixedUpdate()
{
angle = myTrans.eulerAngles.magnitude * Mathf.Deg2Rad;
//rotate object Right & Left
if (Input.GetKey (KeyCode.D))
{
myRot.z -= rotationSpeed;
}
if (Input.GetKey (KeyCode.A))
{
myRot.z += rotationSpeed;
}
//move object Forward & Backward
if (Input.GetKey (KeyCode.W))
{
myPos.x += (Mathf.Cos (angle) * speed2) * Time.deltaTime;
myPos.y += (Mathf.Sin (angle) * speed2) * Time.deltaTime;
anim.SetBool("Swim", true);
}
else
{
anim.SetBool("Swim", false);
}
if (Input.GetKey (KeyCode.S))
{
myPos.x += (Mathf.Cos (angle) * -speed2/3) * Time.deltaTime;
myPos.y += (Mathf.Sin (angle) * -speed2/3) * Time.deltaTime;
}
myTrans.position = myPos;
myTrans.rotation = Quaternion.Euler (myRot);
}