|
i have a 2D game, using the x,y axes to move around the screen and a player that shoots bullets torwards the screen. i got different scripts for the missile script, either addForce to the bullet or make the position of the bullet go towards the mouse Now how to i make it so i shoot at an angle like instead of shooting one bullet directly towards the mouse when i level up i shoot instantiate 2 bullets at a fixed angle away from the mouse position? thx u OR this is another way of shooting towards the mouse if u prefer that way EDIT This is the new code which DOES shoot at an angle but the closer the mouse pointer the slower the bullet speed, i think i had this problem b4 but didnt notice it somehow O_x i get its because the mouse position changes and im multiplying it to the distance of the mouse position, just dunno how to fix that. in UPDATE Function() EDIT again(my bad i put worldPos instead of targetDelta here which was wrong) EDIT yet AGAIN :) :) :) :) cause I FIXED IT!! woot! used targetDelta.normalized and it works, which is surprising since im dont rly know wat it does and it was my 1st guess which i didnt even know where i should have started xDDDD
(comments are locked)
|
|
The easiest way would be to put an offset in your AddForce script! There are a few ways of doing this, but the one I like involves taking the rotation from another transform in the scene-
EDIT: Alternatively,
Alternatively alternatively,
Then you don't have to worry about putting in a new transform, but you have to know exactly what angle you want it to shoot at. umm appreciate the help but dont understand it fully, just to make things clearer is this like a grenade effect? and not sure wat kind of force i should apply either. but let me make things much simpler for the both of us and edit my question with code, and also if its ok javascript would be better, the code above isnt a problem just for the future.
Sep 29 '11 at 12:45 AM
leonalchemist
You said you were using Addforce! Either way, the code will work for transforming vectors however you choose to use the resultant value.
Sep 29 '11 at 01:32 AM
syclamoth
i am using either AddForce or that other script, whichever makes my live easier i'll use rly. but any help using my script above, and cant rly tell wat to set the bulletAngleOffset to either, im a bit lost :/
Sep 29 '11 at 01:37 PM
leonalchemist
you set bulletAngleOffset in the editor, by dragging a transform onto the little box! Then, to change your angle, rotate that transform until the angle is correct. You can use this with things like Transform.LookAt on your secondary transforms, and make secondary auto-turrets! I know that's not what you wanted here, I'm just suggesting other things you could do with this code.
Sep 29 '11 at 01:39 PM
syclamoth
wat im saying was where should that bulletAngleOffset be set to, the player's position? the mouse position? and doesnt seem like it would work in my case cause watever the rotation its gonna aim towards the mouse. and i already have auto turrets in another game :P
Sep 29 '11 at 01:51 PM
leonalchemist
(comments are locked)
|
|
Anyway im posting the answer here for anyone thats interested, thx to syclamoth for the help and so far this script seems to work perfectly fine, now i can sleep soundly tonight knowing i managed to fix it :P
(comments are locked)
|
