Question by
PhysicalBeef · Nov 29, 2015 at 01:38 AM ·
rotationjavascriptphysicsraycastcontroller
Have 3 raycast rays on a capsule and rotate them correspondingly
I'm creating my own physics system, and I need a collision system. How can I work around this? Or do something else to fix this? I could really need some help. This is my script:
if(Physics.Raycast (transform.position, transform.forward, 0.8)) {
}else{
if(Physics.Raycast (transform.position-Vector3.left*0.5, transform.forward, 0.8)) {
}else{
if(Physics.Raycast (transform.position-Vector3.left*-0.5, transform.forward, 0.8)) {
}else{
if(Input.GetKey("w")) {
transform.Translate(Vector3.forward * GameHandler.walkSpeed * Time.deltaTime);
}
}
}
}
showcase.png
(17.9 kB)
Comment
You offset vectors Vector3.left*0.5 and Vector3.left*-0.5 are not affected by rotation. Use transform.TransformVector() to express your local offset vectors in global axis:
if(Physics.Raycast (transform.position, transform.forward, 0.8)) {
}else{
if(Physics.Raycast (transform.position- transform.TransformVector(Vector3.left*0.5), transform.forward, 0.8)) {
}else{
if(Physics.Raycast (transform.position-transform.TransformVector(Vector3.left*-0.5), transform.forward, 0.8)) {
}else{
if(Input.Get$$anonymous$$ey("w")) {
transform.Translate(Vector3.forward * GameHandler.walkSpeed * Time.deltaTime);
}
}
}
}
Hope that helps.