Jump to content
Sign in to follow this  
AngusHeaf

Position objects in a 90 degree cone

Recommended Posts

So I'm working on a mortar deployment script to go along with Upminder's russian mortar. For those you know how mortars work in real life with aiming stakes you will get the idea. But I'll go into that later. Anyways, I need help with a script that's beyond my mathematical abilities.

Basically, I want to take an object and get the direction it is aiming [not a problem]. Now the mortar I'm using as a 90 degree cone of fire [not a problem]. In front of the mortar I want to place 4 pole objects. Each pole should be 5m away from the mortar and evenly spaced 30 degrees apart within the 90 degree cone of fire [problem]. Look at diagram below...

cone.jpg

If the red square at the bottom of my diagram is the mortar (or gun or whatever) object I'm getting the direction on, then the blue squares are the 4 different objects I want to position in front of it. Notice how the dashed line formed a 90 degree cone. If you divide that cone into 3 sections (with 4 total poles) then each slice of the pie so to speak is 30 degrees. Get the idea? Obviously the problem is that the direction of the first object isn't always going to be a nice number like 0, 90, 180, 360.

Basically, I don't know how to do the trig required to calculate the correct values so that I can then setPos my poles. I'm rusty with my Pythagorean Theorum when it comes to calculating triangles when you know 2 angles and the hypotenuse. Any help on how I would calculate where these poles go?

Share this post


Link to post
Share on other sites
Guest jacobaby

I hate maths too, but here goes........

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

_pos = getpos player

_dir = direction vehicle player

_fwdpos=5

_x = ((_pos select 0) + (cos(_dir-90)*_fwdpos))

_y = (( _pos select 1) - (sin(_dir-90)*_fwdpos))

stake = "stakename" camcreate [_x,_y,0]

<span id='postcolor'>

Now, I THINK that will give you the stake 5 m in front of your position. You can play around with the _dir - 90 part to place the poles on a different place at the same 5m radius.

I havent had time to test this, but its something very like that that you need.

TJ

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  

×