Jump to content

Entity direction to point


f13rce
 Share

Recommended Posts

Ok, I'm trying to make an enemy looking at the player. I made a Vec3 named 'botrotation' and made them standard 0.

In the while function I assigned this piece of code:

 

botrotation.Y=asin((camerapos.Y)/(EntityDistance(BasicBot,player)))); //Looking up and down
botrotation.Z=acos((playerpos.Z-botpos.Z)/(EntityDistance(BasicBot,player))); //Looking left and right
PositionEntity(BotModel,Vec3(botpos.X,botpos.Y,botpos.Z)); //Making sure the model is at its position
botpos=EntityPosition(BasicBot);
RotateEntity(BotModel,botrotation);
RotateEntity(BasicBot,botrotation);

 

The BotModel is the character model of the bot.

BasicBot is the bot itself.

 

When I mess around with this code then either the model is just completely gone (not even under the ground or so),

or it is just steady and doesn't move at all.

 

So here is my question: How do I make the enemy look at me?

 

Cheers,

 

Ivar/Evayr

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

How do I make the enemy look at me?

 

PointEntity ?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

PointEntity ?

 

*Sigh* I feel so silly.. lol.

It worked, thanks. :)

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Yes but take in account that if the player and the enemy are at different heights then the enemy would be rotated up or down.

I think you want this only on the Y axis in which case you can use ATan2(playery-enemyy,playerx-playerx) (not sure if this command exists in leadwerks but it's in math.h anyway)

I create the game you play. I create the rulles you will obey.

Link to comment
Share on other sites

In this code

PointEntity(BotBasic,cam,botrotation.X,botrotation.Y,botrotation.Z);

I noticed you only have to say "botrotation.Y=0" and it won't turn up :(

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

In this code

PointEntity(BotBasic,cam,botrotation.X,botrotation.Y,botrotation.Z);

I noticed you only have to say "botrotation.Y=0" and it won't turn up :(

 

has the pointentity command changed parameters? I thought it was:

PointEntity( TEntity entity1, TEntity entity2, int axis=3, flt rate=1, flt roll=0 )

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...