- Home /
My object acts wierd, 2 balls being shot instead of one (from different position)
the ball should be shot from one position, not two here is the code:
public var snowballPrefab : Transform; public var snowballSpeed : float = 6000;
function Update(){ if(Input.GetButton("Fire1")) { if(!snowballPrefab || !snowballSpeed) { Debug.Log("[Shoot] 'bulletPrefab' or 'bulletSpeed' is undefined"); }else{ var snowballCreate = Instantiate(snowballPrefab, GameObject.Find("SSpawnPoint").transform.position, Quaternion.identity); snowballCreate.rigidbody.AddForce(transform.forward * snowballSpeed); } } }
It's acting very wierd. I use a Object as Spawn Point, One prefab as bullet, and everything is set up properly, but there are 2 bullets from two points shot instead of from a point.
Here's my own question for you. Can you check in the editor if you actually see two objects with (clone) behind them come up if you shoot once? And is it possible you really just have one object but the components aren't in the same place making it look in the scene view (not game view) as if there are two? If not I will gladly dig through the code sample you provided
I replaced the prefab, rebuilt it, still the same behaviour, and there is something even more strange There are 2 bullets (snowballs) created one from the point specified and one under the mesh (character - player)
Sorry for the late response, haven't been yesterday at my workspace.
Answer by Mike 3 · Nov 17, 2010 at 04:36 PM
Use GetButtonDown instead of GetButton, the latter returns true every frame that the button is held down
Answer by LFZ2 · Nov 18, 2010 at 12:06 PM
EDIT 2: Now it's creating one instance of the object:) Point achieved. Is there any way I can make my "spawn point" unmovable? it seems to move down as I shoot.
Your answer
Follow this Question
Related Questions
How to shoot a bullet to curser position? 2 Answers
Bullet not always shooting in forward direction. Code included. 2 Answers
Get animation work 1 Answer
Shooting multiple grenades with joystick 0 Answers
Converting button to mouse click 1 Answer