Ooops
October 28, 2021, 17:46:58

Author Topic: Determining if saucer is in my sights PureBasic  (Read 2376 times)

Offline Pfaber11

  • Hero Member
  • *****
  • Posts: 823
  • Bonjour
Determining if saucer is in my sights PureBasic
« 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 .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen.

Offline Pfaber11

  • Hero Member
  • *****
  • Posts: 823
  • Bonjour
Re: Determining if saucer is in my sights PureBasic
« Reply #1 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.  ???
« Last Edit: November 23, 2019, 19:48:42 by Pfaber11 »
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen.

Offline Pakz

  • Full Member
  • ***
  • Posts: 220
    • My homepage
Re: Determining if saucer is in my sights PureBasic
« Reply #2 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.

Offline Kris

  • Full Member
  • ***
  • Posts: 111
Re: Determining if saucer is in my sights PureBasic
« Reply #3 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
« Last Edit: November 24, 2019, 05:52:00 by Kris »

Offline Pfaber11

  • Hero Member
  • *****
  • Posts: 823
  • Bonjour
Re: Determining if saucer is in my sights PureBasic
« Reply #4 on: November 24, 2019, 09:32:14 »
Thanks for the info guys gonna try your suggestions .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen.

Offline Pfaber11

  • Hero Member
  • *****
  • Posts: 823
  • Bonjour
Re: Determining if saucer is in my sights PureBasic
« Reply #5 on: November 24, 2019, 10:33:35 »
Hey Kris got this working
Code: [Select]
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.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen.

Offline Derron

  • Hero Member
  • *****
  • Posts: 3675
Re: Determining if saucer is in my sights PureBasic
« Reply #6 on: November 24, 2019, 11:18:01 »
Code: [Select]
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

Offline Kris

  • Full Member
  • ***
  • Posts: 111
Re: Determining if saucer is in my sights PureBasic
« Reply #7 on: November 24, 2019, 14:25:16 »
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.

Offline Pfaber11

  • Hero Member
  • *****
  • Posts: 823
  • Bonjour
Re: Determining if saucer is in my sights PureBasic
« Reply #8 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.
« Last Edit: November 24, 2019, 17:53:17 by Pfaber11 »
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen.

Offline Matty

  • Hero Member
  • *****
  • Posts: 1369
    • MattiesGames
Re: Determining if saucer is in my sights PureBasic
« Reply #9 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.
« Last Edit: November 25, 2019, 07:04:22 by Matty »
I eat cheese in the trees when its eight degrees

Offline Pfaber11

  • Hero Member
  • *****
  • Posts: 823
  • Bonjour
Re: Determining if saucer is in my sights PureBasic
« Reply #10 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 .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal