x


Update instantiation position when strafing

Hi,

The problem is when I am strafing the character left or right and I instantiate a projectile, the projectile is instantiated 'late' and does not remain in front of the player. Is there a way to update the position somehow?

I know that the multiplication assignment operation "*=" can be applied to rotations, but it cannot be applied to a transform.position, it seems like I would use something like that?

public class ScriptA : MonoBehaviour {

private bool instPrefab = false;

    void Update() 
    {
        if (Input.GetKeyDown(KeyCode.LeftControl)) {
            instPrefab = true;
            ScriptB.SetVelocity(5);
        }
    }
}

public class ScriptB : MonoBehaviour {

public GameObject prefab;

    void Update() 
    {
       if (ScriptA.instPrefab) {
           //get velocity that we set
           Instantiate(prefeb, transform.position, transform.rotation);
           ScriptA.instPrefab = false;
       }
    }    
}
more ▼

asked Apr 26 '11 at 01:37 AM

lampshade gravatar image

lampshade
391 84 92 109

posting your code or at least a better description of it's structure could help others to answer your question easily!

Apr 26 '11 at 01:45 AM Ashkan_gc

Could you explain to me again if this is possible with the code above (edited)?

Apr 26 '11 at 04:09 AM lampshade
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

if you do the instantiation and character movement / rotation in the same event (update or fixedupdate) then there should be no problem but yes if you do one of them in physics frames (i.e FixedUpdate) and another one in normal frame (i.e Update) then it could happen!

if you use the same event for both so if your code is correct, first you check the input for rot/movement and do that and then do the Instantiation everything will be ok.

more ▼

answered Apr 26 '11 at 01:45 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

I am statically communicating with two scripts to make the instantiations..From what you are telling me, that is the problem?

Apr 26 '11 at 01:58 AM lampshade
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x85
x7

asked: Apr 26 '11 at 01:37 AM

Seen: 570 times

Last Updated: Apr 26 '11 at 02:01 AM