Make AI shoot when player is in line of sight

Game Editor comments and discussion.

Make AI shoot when player is in line of sight

Postby tvz » Sat Mar 29, 2014 2:45 pm

Hello,
I am working on a platformer in which we use guns, frags, etc.
How can i make AI/computer shoot only when player comes in line of sight :?: . If there is any object breaking the line of sight of AI then it should not shoot/fire and this applies for both directions.
Please help
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Make AI shoot when player is in line of sight

Postby skydereign » Sat Mar 29, 2014 8:45 pm

Have you looked at this? http://game-editor.com/forum/viewtopic.php?f=6&t=6067&p=42535

You need some way of determining line of sight, and then simply use an if statement in the actor's draw (or similar).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Make AI shoot when player is in line of sight

Postby tvz » Sun Mar 30, 2014 5:22 am

Thankyou
but I did not understand only one function in his code
Code: Select all
float xspeed;
float yspeed;

void gothisway(float ang,float speed)
{
xspeed=-cos(degtorad(ang))*speed;
yspeed=sin(degtorad(ang))*speed;
}

I don't know how to USE cos, sin, degtorad functions and what they do. :(
May you please tell me their use
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Make AI shoot when player is in line of sight

Postby CrackedP0t » Mon Mar 31, 2014 3:03 am

cos() is Cosine, sin() is Sine. Cosine and Sine are used in trigonometry, if you didn't know, and have to to with determining side lengths of right triangles from angles. degtorad() is converting degrees to radians. I can explain a little trigonometry if you'd like, but if you really want a good understanding, you need to take a class on it.
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: Make AI shoot when player is in line of sight

Postby tvz » Tue Apr 01, 2014 4:56 pm

Thankyou for your reply
I know about these sin and cos, these are used in right triangles to find the lengths of sides etc, but I did not understand what that code is doing in above post.
I have not left.
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Make AI shoot when player is in line of sight

Postby lcl » Tue Apr 01, 2014 5:47 pm

By looking at the code, it seems to be designed to make it possible to move an actor to a desired direction without using angle & directional_velocity but just by manipulating it's x and y coordinates or by using xvelocity and yvelocity.
What the function does, is to get the correct modification values for x and y and then storing them to variables xspeed and yspeed.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Make AI shoot when player is in line of sight

Postby tvz » Wed Apr 02, 2014 4:04 pm

Now i understand what this code does.
Thanks
sin^2(θ)+cos^2(θ)
for you all
I have not left.
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest