I have a character with two raycasts on it. The movement controls change depending on which raycast is in contact with a collider. This is done with a boolean (in Java Script):
The problem is, the controls will begin as control-set 1. when the 2nd raycast hits a collider, it will change to control-set 2. When raycast 1 then hits a collider, it won’t change the controls.
So what i need is: If raycast 1 is touching a collider and then raycast 2 comes into contact with a collider, automatically default to raycast 2 and vice-versa.
Code please, im having a hard time understanding what you mean.
You could just make an if-sentence stating that if raycast 2 is null, then it should use raycast 1.
Edit:
private GameObject hGO;
private GameObject h2GO;
void Update () {
RaycastHit hit;
RaycastHit hit2;
//cast the first ray, this one goes down
if(Physics.Raycast(transform.position, -Vector3.up, out hit, 100f)){
hGO = hit.collider.gameObject;
}else{
hGO = null;
}
//cast the second ray, this one goes up
if(Physics.Raycast(transform.position, Vector3.up, out hit2, 100f)){
h2GO = hit2.collider.gameObject;
}else{
h2GO = null;
}
//prioritize between the different controls
if(h2GO != null)
{
Debug.Log("using set two");
}
else if(hGO != null)
{
Debug.Log("using set one");
}
else
{
Debug.Log("using something else");
}
}
this would have worked if you had only had 3 controls, you should be able to adapt it into 4 controls if you play around with it for a bit.
playing around with as many bools as you’ve got is just silly
Check my first answer, i've updated it with some code that might help, its in c# though, you only need to change it into javascript, shouldnt be too hard :)
holy batshit, you could also just have edited into your own post, instead of making a new answer :)
– Kacerbut yeah, i think i understand what it is you want, basically you want a game where you can walk on walls and cielings, if im not wrong.
– KacerCheck my first answer, i've updated it with some code that might help, its in c# though, you only need to change it into javascript, shouldnt be too hard :)
– Kaceroh yeah, also you would want to look at "input.getaxis" http://unity3d.com/support/documentation/ScriptReference/Input.GetAxis.html
– Kacer