- Home /
Is there any flying bug scripts out there?
Hey everyone! I've had Unity for about a month now, and I figure it's time to make my first game. It's going to be more of a simulation game than a regular game, but it's going to basically be about this robotic fly in a modern-day living room. However, I'm still just learning Javascript, and I don't have the ability to create a code as of right now that allows the fly to "fly," move forward, backwards, left and right.
So far I've got this, but it's very choppy/not smooth as I would like it. The game is a simulation game and I would love it to have a nice, smooth feel to it. #pragma strict
var walkspeed: float = 5.0;
function Start() {
}
function Update() {
rigidbody.freezeRotation = true;
if (Input.GetKey("space")) rigidbody.AddForce(0, 2, 0);
if (Input.GetKey("d")) transform.Translate(Vector3(-1, 0, 0) * Time.deltaTime * walkspeed);
if (Input.GetKey("a")) transform.Translate(Vector3(1, 0, 0) * Time.deltaTime * walkspeed);
if (Input.GetKey("w")) transform.Translate(Vector3(0, 0, -1) * Time.deltaTime * walkspeed);
if (Input.GetKey("s")) transform.Translate(Vector3(0, 0, 1) * Time.deltaTime* walkspeed);
}
The flying is triggered by pressing the space bar and the rest is just wsad movement, I just found this script somewhere on the forums and edited a little bit. So back to the question, is there anyone that has a better script out there for flying bug movement? Or, can you please edit this one to improve it?
Any help is greatly appreciated, and thank you in advance!
Sorry to bump, but this is still troubling me.
There anyone out there who can help?
i think this is what you are looking for if you want to make it your self link text
change the var (everywhere, not just at the top) in something like :velocityup add an extra var like velocityup, only now down, make the number -8 for example, you can change it to what ever you want make the var gravity : float = 0; ins$$anonymous$$d of 20.0;
remove the if statement about grounding inlcuding the starting { and the ending }
add an extra button like: if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; (where jumpspeed should be velocityup now) change it to the keys you want for the flying so you wil get for example if(Input.Get$$anonymous$$ey("q")) moveDirection.y = velocitydown or up, what ever you want
Answer by aldonaletto · Nov 06, 2013 at 01:24 AM
AddForce works more smoothly in FixedUpdate, and you don't have to freeze rotations every Update. You can also simplify a lot the code with Input.GetAxis:
var walkspeed: float = 5.0;
function Start() {
rigidbody.freezeRotation = true;
}
function FixedUpdate(){
if (Input.GetKey("space")) rigidbody.AddForce(0, 2, 0);
}
function Update() {
var dirX = Input.GetAxis("Horizontal"); // read A/D keys
var dirY = Input.GetAxis("Vertical"); // read W/S keys
transform.Translate(Vector3(dirX, 0, dirY) * walkspeed * Time.deltaTime);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613121156im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Objects cloning on movement? 1 Answer
User Scripts not showing in "Add component - scripts" 6 Answers
Variable Script "movement" 2 Answers
Airplane Script Control 1 Answer
Saving/ Loading Script Weird Bug 1 Answer