Please note that I am only using the forum, opposed to the answers, because it seems not to be working at the moment. Sorry if this is not what the forum is meant for (I actually have never used it before).
Hello everyone,
I have a square character, that walks around the scene. I do not want to use character controller for a number of reasons, also I do not want to use rigidbody. To keep the character from walking through walls I have been using:
var fwd = transform.TransformDirection (Vector3.forward);
var right = transform.TransformDirection(Vector3.right);
var left = transform.TransformDirection(Vector3.right * -1);
var back = transform.TransformDirection(Vector3.forward * -1);
var down = transform.TransformDirection(Vector3.up * -1);
var up = transform.TransformDirection(Vector3.up);
if (Physics.SphereCast (transform.position, gameObject.width, up, hit, 0.01)) {
MoveUp = false;
}else{
MoveUp=true;
}
if (Physics.SphereCast (transform.position, 1, gameObject.width, hit, 0.01)) {
MoveDown = false;
IsGrounded = true;
}else{
MoveDown = true;
IsGrounded = false;
}
if (Physics.SphereCast (transform.position, 1, gameObject.height, hit, 0.01)) {
MoveForward=false;
}else{
MoveForward=true;
}
if (Physics.SphereCast (transform.position, 1, gameObject.height, hit, 0.01)) {
MoveRight=false;
}else{
MoveRight=true;
}
if (Physics.SphereCast (transform.position, 1, gameObject.height, hit, 0.01)) {
MoveLeft=false;
}else{
MoveLeft=true;
}
if (Physics.SphereCast (transform.position, 1, gameObject.height, hit, 0.01)) {
MoveBack=false;
}else{
MoveBack=true;
}
Suddenly, (I am not exactly sure what) this stopped working.
I also tried:
function OnCollisionEnter(hit : Collision)
{
if (hit.transform.position.x > transform.position.x) {
MoveRight = false;
}
if(hit.transform.position.x < transform.position.x){
MoveRight = false;
}
if (hit.transform.position.y > transform.position.y) {
MoveUp = false;
}
if(hit.transform.position.y < transform.position.y){
MoveDown = false;
IsGrounded = true;
}
if (hit.transform.position.z > transform.position.z) {
MoveForward = false;
}
if(hit.transform.position.z <transform.position.z){
MoveBack = false;
}
}
function OnCollisionExit(hit:Collision){
if (hit.transform.position.x > transform.position.x) {
MoveRight = true;
}
if(hit.transform.position.x < transform.position.x){
MoveRight = true;
}
if (hit.transform.position.y > transform.position.y) {
MoveUp = true;
}
if(hit.transform.position.y < transform.position.y){
MoveDown = true;
IsGrounded = false;
}
if (hit.transform.position.z > transform.position.z) {
MoveForward = true;
}
if(hit.transform.position.z <transform.position.z){
MoveBack = true;
}
}
1282709–58005–$PlayerMovement.js (3.76 KB)
Neither of these seem to be working.
All help is apprectiated,
Thanks,
Thor