If something infront then stop

Hello guys,
one fast question. I am trying to make an object( a box) to move from one place to another. While moving i want it to check if there’s something in front ot it. And if there is, then the object should stop moving and “wait” for other command. And my question is: which handler will be most efficient for this job(detecting if there is something in front of the object), or if i need a handler at all to do this?


You could use a sphere in front of your model, and use setTangible(False) to allow it to go through objects. Then, use an event or queue handler to stop your model when it collides. If you use a pusher, you can add it to the same pusher and use it as event handler.

Thank you, i’ll try what you suggested.


Okay, this is what i wrote. It works fine. There’s one last question, is there a way to check for collisions before the main loop and not in it? (Eddited)

#include "pandaFramework.h"
#include "collisionNode.h"
#include "collisionSphere.h"
#include "genericAsyncTask.h"
#include "cIntervalManager.h"

#include "collisionHandlerQueue.h"
#include "cLerpNodePathInterval.h"
#include "cMetaInterval.h"

PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr(); 

int main(int argc, char *argv[])
   PandaFramework framework;
   // Open a new window framework and set the title
   framework.open_framework(argc, argv);
   framework.set_window_title("My window");

   // Open a window
   WindowFramework* window = framework.open_window();

   // Set up the scene
   NodePath camera = window->get_camera_group();
   camera.set_hpr(1.24346, 0, 0);

   // Load Actor, set possition and scale, reparent to render
   NodePath pandaActor = window->load_model(framework.get_models(), ".../models/frowney.egg");
   pandaActor.set_pos( -5, 0, 0 );

   // Create ColSolid, Set it as not tangible, create ColNode, add to the ColNode
   PT(CollisionSphere) cs = new CollisionSphere(0.5,0,0,0.5);
   cs->set_tangible( false );
   PT(CollisionNode) cSphere_node = new CollisionNode("Sphere");

   // ???
   NodePath colNp = pandaActor.attach_new_node( cSphere_node );

   // ...
   NodePath pandaActor2 = window->load_model(framework.get_models(), ".../models/smiley.egg");
   pandaActor2.set_pos( 5, 0, 0 );

   // ...
   PT(CollisionSphere) cs2 = new CollisionSphere(0,0,0,1.0);
   PT(CollisionNode) cSphere_node2 = new CollisionNode("Sphere2");

   // ...
   NodePath colNp2 = pandaActor2.attach_new_node( cSphere_node2 );

	// Create interval, set start and end pos
	PT(CLerpNodePathInterval) pandaPosInterval;
	pandaPosInterval = new CLerpNodePathInterval("pandaPosInterval", 3.0, CLerpInterval::BT_no_blend, true, false, pandaActor, NodePath());
	pandaPosInterval->set_start_pos(LPoint3f(-5, 0, 0));
	pandaPosInterval->set_end_pos(LPoint3f(6, 0, 0));

	// ???
	PT(CMetaInterval) pandaPace;
	pandaPace = new CMetaInterval("pandaPace");

	// ???
	pandaPace->add_c_interval( pandaPosInterval, 0, CMetaInterval::RS_previous_end);

	// ???

    CollisionHandlerQueue* queue = new CollisionHandlerQueue();
	CollisionTraverser traverser;
	if( queue != NULL )
		traverser.add_collider( colNp, queue );
	traverser.show_collisions( window->get_render() );
   // Main Loop(kind of)
	Thread *current_thread = Thread::get_current_thread();
	while(framework.do_frame(current_thread)) {
		traverser.traverse( window->get_render() );
		if( queue->get_num_entries() == 1 )
		// Step the interval manager

   return (0);