- Home /
Borderlands 2 style vehicle driving!
Hey guys i am making a 3d tanks game and i wanted to know how my tank can move like vehicles from borderlands. Like turret points constantly towards the crosshair(reticule) and vehicle only turns when you accelerate.
My current script is normal forwards-backwards movement, with mouselook x-axis on tank body, and mouselook y-axis on turret. Guys please help and you can either give me the script or show me a rough idea.
Please if its possible tell me also how can i make my turret always point towards the reticule (or the mouse). It'll be a great help :)
Thanks a lot :)
Answer by deltamish · Apr 02, 2013 at 04:36 PM
HI,Here is to make the tank look at the crosshair (let this be a 3d text or sphere) Remove the Mouselook script from the Tank var Crosshair:Transform; var TankTurret:Transform; var speed:float = 5; var TankBody:Transform; var rotationspeed:float = 2; private var horizontal:float = 0;
function Update(){
horizontal= Input.GetAxis("Horizontal");
var Direction:Vector3 = Crosshair.position - TankTurret.position;
TankTurret.eulerAngles = Vector3(0,transform.localRotation,0);
TankTurret.localRotation = Quaternion.Slerp(TankTurret.localRotation,Quaternion.LookRotation(Direction),Time.deltaTime * rotationspeed);///to make the turret always look at the crosshair
if(horizontal !=0){//if you press hrizontal button i.e uparow or W or S or down arrow
var MainDirection:Vector3 = Crosshair.position - TankBody.position;
TankBody.eulerAngles = Vector3(0,TankBody.rotation,0);
TankBody.rotaion = Quaternion.Slerp(TankBody.localRotation,Quaternion.LookRotation(MainDirection),Time.deltaTime * rotationspeed);
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to turn a tank? 1 Answer
Problem with vehicle script 1 Answer
Lock rotation of object 4 Answers
Vehicle Script Debugging 1 Answer