Author Topic: Dark Star Solution Sought  (Read 505 times)

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Dark Star Solution Sought
« on: June 16, 2015, 12:30:42 pm »


               
I have need to do something (described under problem) and have come up with a proposed solution. The trouble is that I don't know if my solution will work and I strongly suspect that there is a better way to achieve what I want to do. So I turn to those more experienced with NwN script than I am.

 

The Problem

 

I have an object that moves an arbitrary distance in an arbitrary direction (that bit I can do). What I need is some form of collision detection. Ideally the object will "bounce" off of all obstructions in a realistic manner.

 

My proposed Solution

 

Is to create a custom trigger and use its OnExit event to detect when the object is about to collide with a wall. This has the disadvantage that it doesn't take into account any placeables that are in the way. Surely there is a better method, but I can't think of one.

 

Any help gratefully received.

 

(Anyone who has seen the movie "Dark Star" may be able to guess precisely what I trying to achieve here)

 

TR


               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Dark Star Solution Sought
« Reply #1 on: June 16, 2015, 06:00:59 pm »


               

I'm no script wizard, but wouldn't any trigger script you make for bouncing from walls work exactly the same if you painted the trigger around placeables?



               
               

               
            

Legacy_CaveGnome

  • Sr. Member
  • ****
  • Posts: 432
  • Karma: +0/-0
Dark Star Solution Sought
« Reply #2 on: June 16, 2015, 11:18:57 pm »


               I would test the trigger "on enter" for a quicker reaction time and use the same "bounce" script called from all triggers positioned in front of the walls. there are various methods to identify the trigger who was entered. for ex. giving explicit tag names to the trigs and capturing the tag name and testing it to choose the correct reaction when something enters. well... I am sure, you will get far better advice from the forum regulars ;-)
               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Dark Star Solution Sought
« Reply #3 on: June 17, 2015, 10:24:56 am »


               

EDIT:


 


You can use waypoints. You'd need a vector map of the area (see below). From the creatures's initial position and direction, calculate the wall intercept. Create a waypoint there and run to it. Repeat for each reflection.


 


You'd need to test whether it's fast enough to look like an elastic collision - there is a slight delay in the action queue to change direction.


 


Triggers could be used, but, by default, all triggers have a facing of zero degrees, and their position is an arbitrary vertex. Rather than mess with that, it's probably easier to store the vector that the wall represents. A convenient way of doing that is a pair of waypoints, one at each end of the wall.


 


You might want to use triggers as a supplement to this method, to simplify the maths of knowing when a collision has occurred, but triggers alone won't hack it. The reason is that NWN actions can move to an object or a location, but not in a direction, so whatever you do, you'll end up moving to waypoints or the like.


 


For placeables, you'd need 4 vectors for a rectangular object, at least 8 for a round object, and so on. To save work, you might store the placeable's shape and dimensions as local variables, then calculate the vectors. Remember, the engine will path find around a placeable unless the creature is moving to a waypoint just in front.


 


If there are creatures in the area, the "ball" will need the cutscene ghost effect, otherwise the engine will apply its own collision avoidance and impact rules. You'd need to be careful with placeables, too, as the engine will path find around them, unless the location moved to is in front of them.