Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


How to make 3D Character move to a specific point


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Cydriic   Members   -  Reputation: 174

Like
0Likes
Like

Posted 08 August 2014 - 03:23 PM

Hi Everyone,

 

I'm having a hard time making my NPC travel to a specific created destination.

 

My NPCs move fine around the world witht their AI that randomizes the m_Roty angle of their direction and if they are moving or not. That works fine.

It's when i'm trying to say : "Go at that specific Location in the world" That I am having problems.

 

To move, my NPC use the following vector definition. 

 

if(m_Move)
{
 
AnimateArms = true;
m_x1 += (float)sin(m_Roty*piover180) * MoveFactor;
m_z1 += (float)cos(m_Roty*piover180) * MoveFactor;
 
}
 
What i;m trying to figure out is how to determine the m_Roty angle at which they will travel to reach the created destination point.
 
Up to now i have done the following but it's not working properly...
 
void CVillager::CreateDestinationPoint(GLfloat a_x1, GLfloat a_z1)
{
 
//CREATE DESTINATION POINT
m_DestPoint = new CDestinationPoint(a_x1, a_z1, TextureLoader->DestPoint[0]);
 
//SET GOING HOME TO TRUE
m_GoingHome = true;
 
//DETERMINE ANGLE OF DIRECTION
if(m_DestPoint->m_x1 - m_x1 <= 0.0f && m_DestPoint->m_z1 - m_z1 >= 0.0f)
{
double angle = ( -( (double)m_DestPoint->m_x1 - (double)m_x1 )/( (double)m_DestPoint->m_z1 - (double)m_z1));
m_Roty = - (GLfloat)atan(angle);
}
 
if(m_DestPoint->m_x1 - m_x1 >= 0.0f && m_DestPoint->m_z1 - m_z1 >= 0.0f)
{
double angle = ( ( (double)m_DestPoint->m_x1 - (double)m_x1 )/( (double)m_DestPoint->m_z1 - (double)m_z1));
m_Roty = (GLfloat)atan(angle);
}
 
if(m_DestPoint->m_x1 - m_x1 >= 0.0f && m_DestPoint->m_z1 - m_z1 <= 0.0f)
{
double angle = -((double)m_DestPoint->m_z1 - (double)m_z1)/((double)m_DestPoint->m_x1 - (double)m_x1);
m_Roty = 90.0f + (GLfloat)atan(angle);
}
 
if(m_DestPoint->m_x1 - m_x1 <= 0.0f && m_DestPoint->m_z1 - m_z1 <= 0.0f)
{
double angle = ((double)m_DestPoint->m_z1 - (double)m_z1)/((double)m_DestPoint->m_x1 - (double)m_x1);
m_Roty = - 90.0f - (GLfloat)atan(angle);
}
 
}
 
Anybody has a lead for me.... The trigonometry seems right, i have sketched it out a lot and I don't see how else I could do it...
 
 
Thanks

Edited by Cydriic, 08 August 2014 - 03:24 PM.


Sponsor:

#2 Zaoshi Kaba   Crossbones+   -  Reputation: 5154

Like
3Likes
Like

Posted 08 August 2014 - 04:28 PM

You should figure vectors; it's along the lines of:

difference = destination - position;
direction = normalize(difference);
movement = direction * move_speed;





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS