Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Using an object Y angle to position another object

Author
Message
Enlightened Gamer
14
Years of Service
User Offline
Joined: 4th Oct 2009
Location:
Posted: 2nd Feb 2010 20:02
Hello,

I have thought of a way to make an easy "field of view" for the animals/objects in my game but I am have difficulties that I would like a little bit of advice with...

I have created a cone that is going to be used as the objects field of view and have it positioned correctly at the load of the game but getting it to move with the object is proving difficult.

I am un able to get the cone to rotate with the object, for example:

once the animal has turned 90 degrees the cone rotates 90 degrees but it is then beside the animal but facing the correct way.

I position the cone infront of the object like this:

position object 2, ob1x#-5,ob1y#+20,ob1z#-300

this should be fine as it is simply using object 1s position to position object 2 but I am unable to successfully get object 2 to position itself infront of object 1 using object 1s current y angle.

Can anyone give me a bit of advice on how this could be done?

Many thanks
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Feb 2010 22:02
This has to do with the pivot point of the cone. The pivot point is what is identified as the "center" or point of origin for the object. Normally, the pivot is smack dab in the center of the object so it rotates around it's core. Not very helpful for a base ball bat or a cone field of view detector.

There are a few ways to approach this. One way is to adjust the pivot point of the object (the cone in this case) so that the pivot is at the sharp point at the top of the cone. This can be done in most 3D modeling programs if you are making the cone in them. This can also be done in dark basic. The nice thing about this is method, once it's done, whenever you rotate it around any axis, it will pivot from where you want it.

Another way is by making the cone a limb of the animal. If you were going to use collision detection as your field of view, then collision would be set for the whole animal. Since the cone is projected outward, you'd probably need to use polygon collision,and that kind of collision can slow things - but in terms of rotation, it is always oriented relative to the main oobject without you having to do anything else.

And yet another way is to use math. There is a simple math way, for rotation just around the y axis, and there is the complex math way for rotation in multiple directions. The complex math way is a little bit more processor hungry and also a bit complicated to understand. The simple math way is pretty straight forward and you can use built in DBC commands.

So for starters, I'll show you the simple math way:

The first thing we want to do is orient the cone to the animal:

set object to object orientation coneobject,animal

This will make sure the cones angles are the same as the animal.

Next we hve to project the cone in front of the animal. If you are rotating on the X and Z plane, that's a rotation around the Y axis - that is the rotation you are describing. There are a few handy built in command in dbc made just for this kind of thing:
newxvalue()
newyvalue()
newzvalue()

Since we are rotating on the x,z plane, we will need newxvalue() and newzvalue(). And since we know we are using the y angle for our rotation, we will be using that as well. All we need is a distance away from our point of origin. This is where the animal will be. How far in front of the animal do we want to put the cone? Let's say 20 units for fun.

Then, we have to position the cone, and then tilt it backwards so that the base is facing outward.



Enjoy your day.
Enlightened Gamer
14
Years of Service
User Offline
Joined: 4th Oct 2009
Location:
Posted: 2nd Feb 2010 22:31
Hello Latch,

I was just about to post my progress as you posted your advice lol

I have go it to nearly work but the problem I am having I think I can fix by setting the orientation of the cone to the animal orientation like you advised so I will try that now.

Anyway here is my progress I was about to post:



Many thanks
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Feb 2010 22:48
I would avoid using newyvalue(). Keep the Y# height fixed or set it some other way. The values returned by newyangle() have never been useful as many times as I've tried to make sense out of it in using DBC.
Perhaps since you are creating obposy# then your code might look like:



Also notice that I made x and z both 300. If you are project forward based on a Y angle, the distance is a combination of the x and z directions, so you have to set the relative distance the same for both. Newxvalue and Newzvalue are using sin and cos to calculate percentages of the 300 in either direction. If the animal is facing 0 degrees y, then the 300 in newxvalue gets calculated to 0. If the animal was facing 90 degrees y, then the 300 in newzvalue gets calculated to 0. If the y angle is 45 degrees, then x and z are calculated at 212.1 each.

As the angle changes, the values returned by newxvalue and newzvalue change. Since you want a position that is a combination of x and z, both newxvalue and newzvalue should be calculated with the same base distance (it's called step value I think in the manual).

Enjoy your day.
Enlightened Gamer
14
Years of Service
User Offline
Joined: 4th Oct 2009
Location:
Posted: 2nd Feb 2010 23:01
The code that I am using now (the code in the post above your last post) is doing what I am wanting apart from it is only ever correct at 0/360 degrees and 180 degress.

While the cone follows the rotation of the animal left and right when the animal is at 90 degrees (for example) the cones point is still in his mouth but the the bottom of the cone is coming out of his backside (180 degrees incorrect).

I am un able to fix this as I can either get the cone to follow his rotation correctly but then it is 180 degrees wrong when the animal is at 0/360 degrees and 180 degress or 0/360 degrees and 180 degress are right but the rest are 180 wrong.

It is very annoying being so close but yet so far away lol
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 3rd Feb 2010 08:39
One important detail I forgot to mention; whenever you set SOMEOBJECT to something elses orientation, you have to reverse the rotation order of the SOMEOBJECT. In this case, the cone has to have it's rotation order reversed when it is created or loaded in.



Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Feb 2010 12:28
And, just to add to this thread, newxvalue and newzvalue are essentially just another way to use cos() and sin().

So this:



Is actually this:



Also, why are you using the angle x in newxvalue, and then the angle y in newyvalue? They should both be angle y of the object.

TheComet


Make the paths of your enemies easier with WaypointPro!
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Feb 2010 19:12
Quote: "newxvalue and newzvalue are essentially just another way to use cos() and sin().
"


Wait........are you saying that they are exactly the same command with differant names or that they can be used for the same thing, Comet?? O_o Im totally confused now.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Feb 2010 20:49
Quote: "Wait........are you saying that they are exactly the same command with differant names or that they can be used for the same thing"

Pretty much, except newxvalue calculates sin , newzvalue calculates cos and I have no idea what newyvalue calculates. It seems to calculate the sin of the opposite angle:



From what I remember, the newvalue commands tend to be a little faster. Probably because the math is already coded in the functions internally.

Enjoy your day.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Feb 2010 22:50
hmmm....wow, never knew that latch.......cool.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Feb 2010 00:44
Quote: "and I have no idea what newyvalue calculates."


LOL

I thought newxvalue() calculates cos and newzvalue calculates sin?

TheComet


Make the paths of your enemies easier with WaypointPro!
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 18th Feb 2010 00:46
Quote: "LATCH: Pretty much, except newxvalue calculates sin , newzvalue calculates cos"


Quote: "COMET:I thought newxvalue() calculates cos and newzvalue calculates sin"


Lol.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )

Login to post a reply

Server time is: 2024-04-26 15:07:25
Your offset time is: 2024-04-26 15:07:25