Jump to content
Sign in to follow this  
monty67t

Set Height Of Spawned Unit

Recommended Posts

Hey guys, got a question for you. I'm using the script below to spawn two insurgents. When the script executes, the units spawn at the location of two game logics. I'm trying to spawn them on roof tops, but even after I set the height of the game logics, it's still spawns them on the ground.

SPAWN SCRIPT

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

?!(local Server) : exit

_insurgent1 = "insurgent1" createVehicle getpos gamelogic1

_insurgent2 = "insurgent2" createVehicle getpos gamelogic2

exit

GAME LOGIC HEIGHT SET USING THE FOLLOWING

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

this setpos [(getpos this select 0), (getpos this select 1), 10]

If you have any ideas on how I can make these two insurgents spawn at a desired height, please let me know. Any help is appreciated.

Share this post


Link to post
Share on other sites

Perhaps right after they spawn you could give them a set height command.

insurgent1 setpos [getpos insurgent1 select 0, getpos insurgent1 select 1, 10]

Should work unless my command is wrong. Its been a while since I've done something like that.

Share this post


Link to post
Share on other sites

Well I thought about that, but I can't name the units to be spawned. Insurgent1 and 2 are the classnames of the units, not the name name, lol, if that makes since. Would that still work using the classname?

I'll give it a shot and report back the results.

Share this post


Link to post
Share on other sites

oooh, well then i guess you could spawn them, name them (I forget how, sorry crazy_o.gif), THEN set them to the height, that should do the trick.

Share this post


Link to post
Share on other sites

Yeah, that sounds like it would work. Now I just have to figure out how to name them after they spawn. Thanks for the replies.

Share this post


Link to post
Share on other sites

Do you have to use a script?

When i need to place units at height or roof-tops,i place this in the units init the last number being the height:-

this setpos [(getpos this select 0),(getpos this select 1),8]

Hope that helps? smile_o.gif

Share this post


Link to post
Share on other sites

G'day, I tried it this way with a Marker and it works

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_insurgent1 = "soldierE" createvehicle getmarkerpos "rt"

_insurgent1 setpos [(getmarkerpos "rt" select 0), (getmarkerpos "rt" select 1), 10]

_insurgent2 = "soldierE" createvehicle getmarkerpos "rt1"

_insurgent2 setpos [(getmarkerpos "rt1" select 0), (getmarkerpos "rt1" select 1), 10]

Srry I used East soldiers in my test, are insurjents an Addon?

GL

Odin

Share this post


Link to post
Share on other sites

@ck-claw

Yes, I'm using a script because I am spawning these guys in half way through the mission. That's the whole point. If you notice above in my original post I posted the exact same line of code you posted in your reply.

@Odin

Thanks man, I will give that a shot. Yeah, the insurgents are addons.

Share this post


Link to post
Share on other sites
Guest

To add in a bit about the Z value for hieght

I always use when spawning, the z value in the marker pos and add the needed height for the specific tower/house, whatever.

In actually spawning, this may or may not be required, but its a known fact, that if you try to.. say, get the height of an object or unit/etc by its own x,y,z value, it will not return true Z ground to height, a marker, or object, etc, must be used that sits on the ground to get distance from to the object that is at a certain height, because I believe without it, the height is revealed from sea level I think, not true ground level.

Therefore, if I wanted to get the true height of a unit from the ground that stands on a tower, if I just tried to get the x,y,z value, z value is improper.

The only way to do that, would be to have say, a marker placed directly under him, and check distance between the marker and the unit - then add in that result to the z value of the units array pos - thats just fyi anyhow about how Z value works

Anyhow, I have reliably used the same method as =Odin= described, except, again, I always add the height desired to the z value of the marker or object.

;from a script of mine, where the particular proper tower height to teleport to is 4 in this case.

_TowerHeight = 4

_Destination = getmarkerPos "TowerPos1"

;tower guards

_UnitName setPos [_Destination select 0,_Destination select 1, (_Destination select 2) + _TowerHeight];doStop _UnitName

Also, setPos is always needed after spawning a unit, at least in my experiences, because the initial spawn will move the unit away from any objects near by (like a house tounge2.gif)

And might want to use the SetUnitPos command in there to, force them up to have a clear view to fire from, or even maybe set it to middle if they can still see good?

I always have tower guards watching a marker pos as well, in the desired direction to face, and I disable their ai Target, to prevent them from chasing after targets, but they still fire on them. In retrospect ive found disable ai "move" to be a less than desirable command to keep them there, they dont respond to doWatch, and it seems to just limit them too much, doStop and disableAi "TARGET" have done perfect for me.

Share this post


Link to post
Share on other sites

Lol ,sorry my bad! smile_o.gif

Posted just before i went to work,should really not post when im sober! biggrin_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×