Script Problem: my instantiates move -- ISSUE RESOLVED

**EDIT:**This issue has been resolved! Here is the resolution to the weak problem:

I didn’t make a prefab.

Yep, that was it. I thought I had, I had a working launcher…well minus the translating…and moved on. I started worrying about what the CODE was doing to my ragdoll launcher without remembering that in a moment of haste I simply dragged a ragdoll to the scene, targeted it for the INSTANTIATE script and never actually made a PREFAB of the ragdoll and then target the script to instantiate the prefab.

The world space location from the ragdoll hanging in the scene off to the side was getting instantiated along with its location and each instantiate was moving on account of it.

Major whoops on my part, but when I discovered this problem this morning in the lab I was more happy about it being fixed than ashamed of myself. :slight_smile:

Thanks for those who tried to resolve my issue anyway even without having the VITAL piece of data where I hadn’t yet created the instantiate’s prefab. :smile:

Thanks for reading this. I couldn’t get my full point across in the title alone.

My script:

var ragdoll : GameObject;
var projectileSpeed : float = 50.0;

function Update() {
    if (Input.GetButtonDown("Fire3")) {
        FireCannon();
    }
}

function FireCannon () {
        var rocketClone = Instantiate(ragdoll, transform.position, transform.rotation);   
      
        var brootjoint = rocketClone.transform.Find("Rag_Root/Rag_MidSpine/Rag_Head"); 
      
        brootjoint.rigidbody.velocity = transform.TransformDirection (0, projectileSpeed, 0);
}

Pic of the situation:

What does work just fine:
It does instantiate the ragdoll prefab no problem
Launches the ragdoll with the Rag_Head joint in front
Launches it on the axis I want and the speed I desire

The Problem I am having:
Each instantiate is created progressively further behind the previous.
Depending on how long it has been since the scene was started the prefab loads more below the intended starting point.

What I mean, is that I have created an empty game object called “RagdollLauncher1” to which I have attached this script. Hoping that it would be my “launch spawn point” and it is…for the first one. However, the second time I hit “Fire3” this new instantiate spawns from a point BEHIND the emptygameobject “RagdollLauncher1”.

So if I hit the launcher 5 times, each ragdoll is created behind the other until inevitably a ragdoll gets instantiated INSIDE my cannon geometry and then even from under neath it.

In the pic below I had a hard time hitting command + 4 and the “Fire3” button fast enough so the ragdolls are already falling down but you can see how the 5th-9th instantiate actually instantiated inside the cannon geometry and got stuck:

The ONE part I have figured out is that TIME from load is the culprit causing the movement.

For instance, if I wait 10 secs to launch my first ragdoll, it will spawn from completely underneath the platform the cannon is on. So, it appears that time is the whole problem.

So, does that mean the Function Update() is the problem?

What in my code is telling it to move in relation to time passed?

What better function ? () should I use in this case that would factor out the time passed issue I am apparently having?

Thank you for your help in advance!

Hello,

I’m only guessing here,

Ragdoll rigidbody collider, maybe it’s colliding with the cannon collider if you have colliders in there.

off topic, Calvin? :slight_smile:

Ray

That was my first concern when I placed the Empty game object “RagdollLauncher1”.

In the first pic you can see that I made sure the empty game object was outside and a good distance from any colliders to prevent any problems.

Thanks for responding, but no that shouldn’t be the problem. Since any ragdolls launched in the first 5-7 seconds fly away from the cannon without any collisions. It’s just after that timeframe the new instantiates have moved so drastically they instantiate inside the cannon and eventually even UNDER.

And in response to your offtopic mention of “calvin?” do you not like Calvin from Calvin and Hobbes? Are you surprised that I would make my avatar that or just asking me if that was Calvin in my avatar?

Have you tried logging transform.position so you can see if it is indeed moving (for whatever reason) ?

I have not tried that. That is a good approach. I mean, I know the location of the emptygameobject where the script resides is not translating, but the location of where the prefabbed ragdoll appears is moving.

From what I can see, the script itself doesn’t appear to be moving the instantiates from their original spawn point…but something external may be interfering causing this issue.

I will try what you suggested to see if there is movement. Thanks!

In the last couple hours I have wondered if a simple issue is occurring because of the hierarchy I have the emptygameobject in. Perhaps my putting “RagdollLauncher1” as a child of the cannon (for purposes of moving it in sync with the rotating cannon) is causing every instantiate to be a child of the previous.

However, they don’t show as children of anything in the hierarchy view as they are instantiated and the first “shot” from the cannon if done after a few seconds of waiting from the moment I hit the play button STILL instantiates from well below the origin I intended with the emptygameobject RagdollLauncher1.

Hmmm…

Thanks for the help so far :smile: I appreciate your time.

Instantiate() doesn’t automatically create children, but the second argument does define the position of the instantiated object. If the object that the script is attached to is moving for whatever reason, your bacon men will be created at different locations.

Nope, looks like the object I attached the script to isn’t budging at all. So that isn’t the problem.

Nothing tangible is actually moving, something in the programming is loading the instances of my ragdoll lower and lower as time goes on.

Thanks though for helping me think through it and at least narrow down options that may have fixed it. :slight_smile:

Guessing here again,

  1. Click on the parent which is the third puzzle and look if there’s any colliders that’s not suppose to be there.

  2. Also look at your ragdoll prefab for any scripts that’s not suppose to be there

As for Calvin, just asking to make sure that it is him, have not seen that image for a long time. Actually love that character!

Ray

Ahh, yeah. That is him for sure. :smile: Glad to see another Calvin and Hobbes fan. Loved that comic strip. Bill Watterson was smart with the way he respected the strip and it’s universe, but man I really wish he had kept writing. Really miss it. :smile:

You actually hit at what the real problem was. Very close.

I discovered what I did wrong this morning. It was just a silly mistake that went unnoticed because I assumed I hadn’t made that mistake. :stuck_out_tongue: [/b]
I will edit the original post to show it has been resolved but here is the resolution to the bizarre problem:
I didn’t make a prefab.
Yep, that was it. I thought I had, I had a working launcher…well minus the translating…and moved on. I started worrying about what the CODE was doing to my ragdoll launcher without remembering that in a moment of haste I simply dragged a ragdoll to the scene, targeted it for the INSTANTIATE script and never actually made a PREFAB of the ragdoll and then target the script to instantiate the prefab.
The world space location from the ragdoll hanging in the scene off to the side was getting instantiated along with its location and each instantiate was moving on account of it.
Major whoops on my part, but when I discovered this problem this morning in the lab I was more happy about it being fixed than ashamed of myself. :slight_smile:
Thanks for those who tried to resolve my issue without having the VITAL piece of data that I had yet created the instantiate’s prefab. :smile:

I wanted to know if anyone has any ideas about other issues that may cause this moving instantiate problem? Everything instantiates as it should with the exception of this problem. I have been trying this for about a week and now I’m completely frustrated. As with the thread starter, my instantiate spawn point moves down over a period of time. My instantiated game object, however, is a prefab. My instantiate code is as such:

var instantball : Rigidbody;
var xVel : float=0;
var yVel : float=0;
var zVel : float=0

shotball = Instantiate(instantball, transform.position, transform.rotation);
Physics.IgnoreCollision(instantball.collider,transform.root.collider);
instant.velocity = transform.TransformDirection (xVel, yVel, zVel);

where I assign xVel, yVel, and zVel within my code. The code is attached to a child (launch position game object) of my third person player. My prefab has gravity applied to its rigidbody and also has a constant force applied to the Y direction. I do not believe that these are an issue, but at this point I have no idea why my spawn point continues to move.

Any help on this matter would be greatly appreciated.

Thanks