SyntaxBomb - Indie Coders

Languages & Coding => PureBasic => Topic started by: Pfaber11 on November 23, 2019, 17:07:26

Title: Determining if saucer is in my sights PureBasic
Post by: Pfaber11 on November 23, 2019, 17:07:26
Been working on something new I have my 3d terrain working nicely and have populated it with flying saucers . I Have my camera moving around the place and have attached it to a sphere for registering if  I get hit by enemy fire . The problem I have is when I have the saucers in my sights I need it to Know it so a light will turn on . The sights are 2d and the saucers are in the 3d world . Tried using the point command without any success . Thoughts on this anyone . Thanks for reading .
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Pfaber11 on November 23, 2019, 19:43:23
Been playing around with point and although it isn't going to help in this situation it may prove useful in the future . So how do I get the computer to respond when my sight is trained on the enemy . Hmm thinking cap on.
  Edit : No idea.  ???
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Pakz on November 24, 2019, 00:49:50
Can you not use a getangle function?

Also firing a series of invisible weapons Per loop to see if it hits anything always helped me before.
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Coder Apprentice on November 24, 2019, 05:00:03

CheckObjectVisibility(#Camera, ObjectID)       - It checks if an object is visible for the specified camera.

PureBasic help file \ Engine3D \ CheckObjectVisibility
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Pfaber11 on November 24, 2019, 09:32:14
Thanks for the info guys gonna try your suggestions .
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Pfaber11 on November 24, 2019, 10:33:35
Hey Kris got this working
If CheckObjectVisibility(0,EntityID(50)) > 0

works well .not sure how it's gonna help me yet although it will help in checking for a missile strike as in knowing which entitys are on screen so it knows which one to check.
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Derron on November 24, 2019, 11:18:01
Quote from: Pfaber11 on November 24, 2019, 10:33:35
If CheckObjectVisibility(0,EntityID(50)) > 0

works well .not sure how it's gonna help me yet although it will help in checking for a missile strike as in knowing which entitys are on screen so it knows which one to check.

(sorry for the almost full quote - but there is not much to cut ...).

Ahemmm ... I am excited to see games in which missiles only strike you if you see them! Must be a world without backstabbing.


Missile hit / whatever hit:
- object coordinates + a hull/bounding box
- player coordinates + hull/bb
- check if boxes collide - and then if hull (more exact)

Think we had this described in another thread already. Learn from it.

bye
Ron
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Coder Apprentice on November 24, 2019, 14:25:16
Quote from: Pfaber11 on November 24, 2019, 10:33:35
works well .not sure how it's gonna help me yet although it will help in checking for a missile strike as in knowing which entitys are on screen so it knows which one to check.

I probably misunderstood you. I thought you want to detect if a saucer is in your "sight" so you can setup a warning light.
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Pfaber11 on November 24, 2019, 17:33:23
Yes Kris that was the idea and I have used checkobjectvisability (entityID) and after a long time got it working very well and it's pretty accurate.
Edit: I spent about 8 hours getting it all working properly and I did it by creating a very small camera like camera 1x1 as small as it can get and put this right in the middle of my sights and pointing straight ahead . When the entity is in the sights it tells me which is what I wanted . Then you press fire and bobs your uncle exploding saucer (yet to be done ) . Still getting 60 fps with all this going on . Got 46 saucers and one other entity.
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Matty on November 25, 2019, 07:02:48
A  dot product between the forwards normalised vector for the camera and the normalised vector from camera to object will give a value greater than zero if it is in the front 180 degrees and grearer than 0.7 if it is in the front 90 degree arc...should help.
Title: Re: Determining if saucer is in my sights PureBasic
Post by: Pfaber11 on November 25, 2019, 16:18:50
Yes got that Ron will need it sooner or later thankyou. Gotta sort out some explosions next . I am thinking the saucers will glow red then explode sorta like war of the worlds style . Gotta have some levels of difficulty as well and saucers fighting back . Long way to go but wanna get it complete before Christmas . Gives me a few weeks to get it done . Anyway that checkobjectvisability() is excellent and it doesn't slow the whole thing down . Moved the camera view off the screen so it can't be seen still works the same . made it's viewing POV to 1 so it's only displaying and reacting to the very center of the screen where the center of my sights are . Never would of considered this before but it gets the job done . I also made the width and height of the camera (1,1) not sure if that makes any difference . I think it is explosion time and am expecting this to take a few days . Never animated an explosion before so this is fresh ground for me . Any advice would be welcome on how to do this .
Have a nice evening .