hai guys…am trying to move a vehicle based on velocity in the terrain which includes ups and down…am using transform.rotate function in 2 different areas for different purpose…one is
when am try to move a car in left side it doesnt take my currnt if condition i,e when am pressing left arrow that line doesnt executed…what can i do…is there any possible solution to use 2 differnt rotation function for same car object without affection each other…thanks in advance…please ignore cases…
I don’t really know what you’re trying to do with the first part of the code you posted, but as for the second part… it’s much easier if you don’t repeat code too much. You can use an axis variable for better control over the transform functions.
public var axis : int;
then you put the Rotate line in Update:
//Note how we are multiplying it to the "axis" variable
transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime * axis);
Basically, your object will begin rotating according to the “axis” variable. If you press Right Arrow, the axis will be 1 and the object will rotate towards the right. If you press Left Arrow, the axis will be -1 and the object will rotate towards the left. If you are not pressing any button, the axis will be 0 and the object will not rotate.
sevensixtytwo is correct. In these situations it’s best to perform your function call only once, only if it has to, and with a value depending on one or more keypresses.