- Home /
Very basic Instantiate Question
Here is my super simple game: https://dl.dropboxusercontent.com/u/33685163/testUnity/testUnity.html
Here is my movement code: http://pastebin.com/HXHTLXyU
My question is how do you make it so that the bullet fires slowly in the direction it's currently facing just like the way tanks shoot in this video: http://www.youtube.com/watch?v=VM6iZgSaeX0
I also want to be able to show the game cursor while playing but when I upload the build the cursor disappears, though I can see it while being in play mode.
The games controls are: mouse click to move the player, and space bar to shoot the bullet.
Thank you very much, I really appreciate all the help from pros like you!
Hey there. You may get a few more responses if you post your code in the actual question rather than link to it :) People are sometimes hesistant to click away from the site.
Have you tried using cloneBullet.addForce(Vector2 force)? For example cloneBullet.addForce(transform.forward * 10f);
Answer by ozku · Jan 16, 2014 at 01:05 PM
moveDirection = transform.TransformDirection(Vector2.right); That should work but I'm not 100% sure because I only know javascript...
Answer by Sir-Irk · Jan 16, 2014 at 01:05 PM
You want to create a float variable to keep track of how much time has passed since your last shot. In your update do something like this
float timeElapsed = 0.0f;
void Update(){
timeElapsed += Time.deltaTime;
}
Then in your shooting code check if timeElapsed is >= your firingRate and reset timeElapsed to 0 every time you successfully shoot a bullet. For example setting firingRate to 0.25f would allow a shot every 250 milliseconds.
Edit1: Also, you can use transform.forward to get the current object's forward direction.
I'd personally recommend moving your shooting code to a separate script though. This makes debugging and modification easier.
Edit2: Another tip: you can make a new gameObject with a transform component and make it a child of your player. You can then put your shooting script(should be seperate form the movement script) on this new transfrom object and adjust it's transform.localPostion. This allows you to easily change the position of where your bullets come from. Just make sure that this child object's rotation is set so that it's forward direction is the same as the parent's forward direction.
I'm not sure about the cursor issue. Do you have any scripts that turn the cursor on or off and/or locks the cursor? Check your player settings for your build and see if there is anything that needs to be changed.
Your answer
Follow this Question
Related Questions
need help with instantiating for making a bullet shoot 1 Answer
Bullet stops when new bullet instantiates pls help 3 Answers
Control amount of bullets 2 Answers
Invoke is not working properly. 0 Answers
Enemy Damage problem 1 Answer