# 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 Professional Discussion / Point one object at another without using "point object" command? How to figure out the Y angle to rotate first object to

Message
Posted: 23rd Sep 2020 05:36
Ok, so long story short, Im using Dark Physics, and therefore the "POINT OBJECT" command isnt an object, because Rigid body physics objects arent affected by DarkBasic's native movement and rotation commands. Once youve made something a rigid body, stuff like "ROTATE OBJECT" and "POINT OBJECT" and "POSITION OBJECT" wont work on them, and you have to use Dark Physics' commands like "PHY SET RIGID BODY POSITION" and "PHY SET RIGID BODY ROTATION."

I basically am trying to make it so that enemies will rotate so theyre facing towards the player when the player gets close enough, and I was planning on using "point object enemy#,PlayerX,PlayerY,PlayerZ" but I cant use that since the enemies are rigid bodies.

Unfortunately, Dark Physics doesnt have its own equivalent of the "POINT OBJECT" command. It only has "SET OBJECT ROTATION." So then, how would I go about figuring out the correct Y angle to set the rotation to, in order to have one object point at another? Like I know that if the player is to the enemy's right, thatd be 90 degrees, if the player is directly behind, itd be 180 degrees, if theyre diagonally behind and to the left itd be 225, etc. But how do I calculate that? I can get the XYZ position of the player, and the XYZ position of the enemy, but I cant wrap my head around how I can use the XYZ coords to figure out the angle.

I realize this is probably an incredibly stupid question with a super obvious answer, but Im terrible at this kind of math so its difficult for me. Any help is greatly appreciated.

Posted: 23rd Sep 2020 10:22
You make a hidden DBP object at the same position as the Dark Physics object and
point that at the player, and then rotate the Dark Physics object the same angles
like this

Posted: 23rd Sep 2020 19:04 Edited at: 23rd Sep 2020 19:07
Quote: "You make a hidden DBP object at the same position as the Dark Physics object and
point that at the player, and then rotate the Dark Physics object the same angles
like this"

I had thought of that, but really didnt want to go that route because itd be essentially doubling the number of objects in my game, which is a jump in processing time I dont need.

I ended up figuring it out with a ton of googling and research and brute force "try this, see if it works, if not then change something, try again, repeat" kind of approach.

In the end, what I settled on was

Looks so simple when you see it like that but this level of math is NOT my strong suit, so it took me a very long time to figure out, and even now I dont truly understand it. I know that using ATANFULL this way will get me an angle, but I dont know how or why. its like knowing that your TV will display images and sounds for you, but having no clue how it does it. I know that ATAN is short for arc Tangent, but I have no clue what a tangent or an arc tangent are or what they do. I know theyre math terms, but beyond that I have no idea.
Posted: 24th Sep 2020 03:16 Edited at: 24th Sep 2020 03:19
OG, you've found the math solution that you need here (using X & Z) but wanted to respond to:
Quote: "itd be essentially doubling the number of objects"

which isn't necessarily true. you can use a single dummy object, place it at the start coords, point it at the target, grab the angle, then place the same dummy object at the next start, point and grab, and so on.
i know it works in AppGameKit fine and believe i used to do the same with DBPro.
[My Itch.io Home] [#LowRezJamAGK2020]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]