Collision Detection with Tiled Map

I have a 32*32 tile map size and also 32*32 size image character. I am having difficulty in having the character avoiding walking through the wall. It keeps moving through the wall. Has anyone ever done any similar things as I am? Just need a simple logic method to detect collision with the wall. Thanks

I usually use simple math against the coordinates of the image to the border of whatever construct is in the way.
My character objects are usually always aware of their specific coordinate values at corners so before a MOVE, I check to see if the coordinates AFTER the move would fall outside of a specified rectangle area of allowable movement.
If my condition checking deems it a legal move then I proceed to move the character( Image, Rectangle, etc...)

Similar Messages

  • URGENT: Collision Detection In Tiled Map

    HELP!!!!! I am creating a tile map of size 32*32. And the character image size is also 32*32. Now i am stuck in making collision with the walls. I have tried my own method but to no avail. Has anyone tried to doing collision detection? Need a simple logic method to detect the collision...
    (Using keyevent to control the character moving around)
    Pls I really appreciate your help!!!!!!!
    Thanks.....

    I assume you have some way of knowing that you need to display a wall tile on the map, so before you move a particular direction check to see if the square you will move to is an acceptable move (no wall, door, mountain, water etc). If it is unacceptable play a little sound or display a message, otherwise do the move.

  • Collision detection with rectangles

    Hi, I'm making a racing game from the top view. My track is made up of many gif files, each connecting to each other. My cars are also gif files, and the player's car doesn't move, it can only rotate by displaying gif files of the car in different angles. Only the track moves to create the effect of the car moving. I am having trouble with the collision detection when the car hits the side of the road and when it hits other cars. I've looked at the discussion by JTeen but my car are rectangles, not circles. Could someone please help me with the following:
    1. What is the best system to define the boundary of the road in the gif files.
    2. Should I use the 4 verties of the player's car to detect the collisions and change the co-ordinates whenever I rotate the car.
    3. My tracks are never actually curved, they are made up of multiple straight lines to create a turn. Should I use the slope of these lines and then create an equation for the lines for the detection?

    sure.
    btw this isn't the way of doing it, its simply a way of doing it.
    In a Sector based track, the track is represented as 2 polygons.
    An inner track edge, and an outer track edge.
    Both polygons have the same number of verticies.
    a screen shot from my track editor would probably explain it better than words... http://www.pkl.net/~rsc/4KApplet/editorGrab.png
    As the car goes around the track, you keep track of which sector it is in by doing a line intersection with either the nextSector or prevSector.
    The code will look something like this [taken from the 4KApplet]
                      //check for entry into the next sector
                      while(Line2D.linesIntersect(x,y,newX,newY,
                            trackX[RIGHT][newNext], trackY[RIGHT][newNext],
                            trackX[LEFT][newNext], trackY[LEFT][newNext]))
                         // if you do enter the next sector, this must loop, until you stop going forward in sectors
                         // if this loop wasn't here, a fast traveling car could potencially jump out of its current sector
                         if(newNext==1) lapChange--;//if the car passes the start/finish line, set the lapChange flag
                         newPrev = newNext; //newPrevious sector is now the old Next sector
                         newNext = (newNext+1)%SEGMENT_COUNT; //and the new next sector is the old next sector +1 (modded for track looping)
                         checkPrevious=false; //the car is going forward, so don't check previous sector gate line
                      if(checkPrevious)
                         //does same as above, but for previous sector
                         while(Line2D.linesIntersect(x,y,newX,newY,
                               trackX[RIGHT][newPrev], trackY[RIGHT][newPrev],
                               trackX[LEFT][newPrev], trackY[LEFT][newPrev]))
                            if(newPrev==1) lapChange++; //if the car is going backward, increment the lapCounter
                            newNext = newPrev;
                            newPrev = (newPrev + (SEGMENT_COUNT-1))%SEGMENT_COUNT;//backward looping by using mod as well :) didn't work this out until now!!
                      }Once you have determined which sector the car is in, you must then do 2 more line intersections to determine if the side of the track has been hit.
    In a Collision Map based track[n], you pre-calculate the 'inside-ness' of each pixel before hand and store it all in a [][], then, whenever you move the car, you simply look into the collisionMap [][] to see if the new point is track or wall.
    This has the advantage that you don't need to keep track of which sector the player is in (though you still have to do 1 line intersection to determine if the start/finish line has been crossed)

  • Sorry for the topic Urgent:Collision with Tiled Map

    I didn't noe it was forbidden........Sorry

    Cross-posting?
    Yeah we tend to frown upon that.
    http://forum.java.sun.com/thread.jspa?threadID=5170123
    http://forum.java.sun.com/thread.jspa?threadID=5170102

  • Collision Detections in Tilemaps

    I need some help with collision detection with tilemaps. I have the following code for the tilemap:
    import java.awt.*;
    public class TileMap {
         final int EMPTY = 0;
         final int WALL = 1;
         private static final int WIDTH = 30;
         private static final int HEIGHT = 40;
         public static final int TILE_SIZE = 15;
         private int[][] map = new int[WIDTH][HEIGHT];
         public TileMap() {
              for (int i=0;i<HEIGHT;i++) {
                   map[0] = WALL;
                   map[29][i] = WALL;     
              for (int i=0;i<WIDTH;i++) {     
                   map[i][0] = WALL;
                   map[i][39] = WALL;
         public void paint(Graphics g) {
              for (int x=0;x<WIDTH;x++) {
                   for (int y=0;y<HEIGHT;y++) {
                        if (map[x][y] == WALL) {
                             g.setColor(Color.RED);
                             g.fillRect(x*TILE_SIZE,y*TILE_SIZE,TILE_SIZE,TILE_SIZE);
    Im finding it hard to find a good tutorial on simple collision detection. Can anyone explain how i would work out some simple collision detection. For example, lets say there is one sprite, how would i figure out which tile the sprite is on? How would i detect the next sprite? Just need the concept.
    Thanks very much.
    Edited by: Java_Jenius on Jun 28, 2009 8:34 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Take a look at http://www.13thmonkey.org/~boris/jgame/ for example.
    It is an open source gaming engine and features sprites and collision detection.

  • Tile Based Collision Detection

    I am following Tonypa's Tile Based Tutorials and I have to
    say, they are great. He covers everything needed, except for one
    thing I am troubled on - Refering to Tutorial 9,
    http://www.tonypa.pri.ee/tbw/tut09.html,
    Stupid Enemy, instead of an enemy I want to make this a NPC who
    walks around in a village. So what do I do to make it so that I, or
    the char, doesn't walk right over the enemy/NPC? I am trying to
    develop an RPG, and it would look silly to have the character walk
    on top of the NPC. Can someone provided a snippet on how to make a
    collision detection with the NPC and not walk on top/under the NPC?
    One last favor to ask: What if I want to talk to the NPC if I
    am within a half tile? Would anyone be willing to share info on how
    this as well?
    Thanks a bunch in advance

    Ok, let me see if I get the read correct here: you have your scenery objects as tiles and when moving your players/NPC's through the scenery you are not scrolling the background as you go, but when you get to s certain point you want to scroll the tiles of the background also, so you can have new scenery cycle in as needed an still have the tiled background objects and new tiled background objects work for collision detection.
    If my take on your project is correct, then you have to make your tiles addressed with relative addressing formulas as you'll probably need to do with your sprites also.
    So the way this will go is that you have to make an offset and add them into your formula based on your character position. Then based on your character position you can choose to scroll your tiles left, right, up, down or what ever you choose to support. As a tile falls fully off the screen, you can dispose of it or cycle back through depending on how you implement your background.

  • Managing multiple collision detection between objects(not necessarily circles)

    Hi.
    I´d like to know if there´s any good tutorial, or if somebody knows, a way, to manage a multiple collision detection with pixel level detection, for objects, not necessarily circles, irregular objects.
    Any help?

    Yes, and what about the speeds of each object?
    I was thinking something like this:
    var  _currentObj1SpeedX = obj1.speedX
    var  _currentObj1SpeedY = obj1.speedY
    obj1.speedX = obj1.speedX - obj2.speedX
    obj1.speedY = obj1.speedY - obj2.speedY
    obj2.speedX = obj2.speedX -  _currentObj1SpeedX
    obj2.speedY = obj2.speedY -  _currentObj1SpeedY
    Is it right?

  • Java3D collision detection (full test source)

    Hello!
    I have struggled with this problem for a month now, so I really need some help.
    I try to develop a game with collision detection with Java3D.
    To narrow it down I had made two test-java-files for you.
    File 1) Applet where I add all my objects (2 ColorCubes)
    File 2) A KeyListener to stear one of the cubes. The key listener also checks for collisons.
    All code is below, just compile and try.
    The idea is that the cube that I can stear should stop outside the other cube from any
    direction. But I can't detect that other cube at all.
    So if any one could try the code and give me some hints or example I would be most
    thankfull.
    Best regards
    Fredrik
    import java.applet.*;
    import java.awt.*;
    import java.awt.Frame;
    import java.awt.event.*;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.behaviors.keyboard.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import javax.swing.*;
    import java.util.*;
    public class Test extends Applet
         BranchGroup branchGroup;
         ColorCube colorCube1 = new ColorCube(0.4); //The cube that you can navigate
         ColorCube colorCube2 = new ColorCube(0.4);
         TransformGroup transformGroup1;
         public void init()
              setLayout(new BorderLayout());
              GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
              Canvas3D canvas3D = new Canvas3D(config);
              add("Center", canvas3D);
              SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D);
              branchGroup = new BranchGroup();
              //Cube1
              transformGroup1 = new TransformGroup();
              Transform3D transform3D1 = new Transform3D();
              transform3D1.set(new Vector3f(0.0f, 0.0f, -20.0f));
              transformGroup1.setTransform(transform3D1);
              transformGroup1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              //for setShapeBounds
              transformGroup1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              colorCube1.setCapability(Node.ALLOW_BOUNDS_READ);
              transformGroup1.setPickable(false);
              transformGroup1.addChild(colorCube1);
              branchGroup.addChild(transformGroup1);
              canvas3D.addKeyListener( new TestListener(transformGroup1, this) );
              //Cube2
              TransformGroup transformGroup2 = new TransformGroup();
              Transform3D transform3D2 = new Transform3D();
              transform3D2.set(new Vector3f(0.0f, 2.0f, -20.0f));
              transformGroup2.setTransform(transform3D2);
              colorCube2.setPickable(true);
              transformGroup2.addChild(colorCube2);
              branchGroup.addChild(transformGroup2);
              branchGroup.compile();
              simpleUniverse.addBranchGraph(branchGroup);
         public static void main(String[] args)
              Frame frame = new MainFrame(new Test(), 600, 400);
    }The KeyListener with Collision detection
    import java.awt.event.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import java.awt.Frame;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.picking.*;
    import com.sun.j3d.utils.geometry.*;
    public class TestListener implements KeyListener
         final static float DISTANCE      = 0.1f;
         final static double TURNANGLE      = 0.1;
         float x = 0.0f;
         float y = 0.0f;
         float z = -20.0f;
         private double angle = 0.0;
         TransformGroup transformGroup;
         Transform3D positionTransform3D = new Transform3D();
         Transform3D angleTransform3D = new Transform3D();
         Test test;
         PickTool pickTool;
         Point3d point3d;
         Vector3d vector3d;
         Transform3D transform3D;
         public TestListener(TransformGroup tfg, Test t)
              test = t;
              transformGroup = tfg;
              pickTool = new PickTool(test.branchGroup);
              pickTool.setCapabilities(test.colorCube2, PickTool.INTERSECT_FULL);
                pickTool.setMode( PickTool.BOUNDS );
              positionTransform3D.set(new Vector3f(x, y, z));
         public void keyTyped(KeyEvent e)
         public void keyPressed(KeyEvent e)
              if( e.getKeyCode() == KeyEvent.VK_UP )
                   if(isMovePossible(DISTANCE))
                        Transform3D temp = new Transform3D();
                     temp.set(new Vector3f(0, DISTANCE, 0));
                     positionTransform3D.mul(temp);
                     transformGroup.setTransform( positionTransform3D );
              else if( e.getKeyCode() == KeyEvent.VK_DOWN )
                   if(isMovePossible(-DISTANCE))
                        Transform3D temp = new Transform3D();
                     temp.set(new Vector3f(0, -DISTANCE, 0));
                     positionTransform3D.mul(temp);
                     transformGroup.setTransform( positionTransform3D );
              else if( e.getKeyCode() == KeyEvent.VK_LEFT )
                angle = angle + TURNANGLE;
                angleTransform3D.rotZ(TURNANGLE);
                positionTransform3D.mul(angleTransform3D);
                transformGroup.setTransform( positionTransform3D );
              else if( e.getKeyCode() == KeyEvent.VK_RIGHT )
                angle = angle - TURNANGLE;
                angleTransform3D.rotZ(-TURNANGLE);
                positionTransform3D.mul(angleTransform3D);
                transformGroup.setTransform( positionTransform3D );
         public void keyReleased(KeyEvent e)
         public boolean isMovePossible(float distance)
              boolean retValue = true;
              PickBounds pickBounds = new PickBounds( test.colorCube1.getBounds() );
              pickTool.setShape( pickBounds, getCordinate(test.transformGroup1) );
              PickResult pickResult = pickTool.pickAny( );
              if ( pickResult != null )
                   System.out.println("Boink");
                   retValue = false;
              else
                   retValue = true;
              return retValue;
         public static void main(String[] args)
              Frame frame = new MainFrame(new Test(), 600, 350);
        public Point3d getCordinate(TransformGroup transformGroup)
              Transform3D pointTransform3D = new Transform3D();
              transformGroup.getTransform( pointTransform3D );
              float[] cordinates = new float[16];
              pointTransform3D.get(cordinates);
              Point3d point = new Point3d(cordinates[3], cordinates[7], cordinates[11]);
              return point;
        public void printOutCordinates(TransformGroup transformGroup)
              Transform3D printOutTransform3D = new Transform3D();
              transformGroup.getTransform( printOutTransform3D );
              float[] cordinates = new float[16];
              printOutTransform3D.get(cordinates);
              for(int i = 0; i < cordinates.length; i++)
                   System.out.println(i + ":" + cordinates);
              System.out.println();

    First of all I would like to point out, that i've never actually used the PickTool, or in fact any element of the whole picking infrastructure from Java3D. Nevertheless I have done some collision detection in Java3D and it worked just fine. Unfortunatelly it required building the whole coldet ( collision detection ) algorythm from scratch :-)
    If You want to collide only two bodies then You probably should consider creating a special Behaviour class that will react to the WakeupOnCollisionEntry and WakeupOnCollisionExit criterions. There is a good example of such a behaviour class in the Java3D demos, under TickTockCollision. However if there will be more bodies in Your scene and they will collide with each other in a random way, then You should rather consider building the whole coldet engine from scratch ( it's not very difficult, but it takes some time )
    Either way, You could try to get a second opinion on the Java3D forum. People out there should have more experience with Java3D

  • 2D Pixel Collision detection on XML tiled map

    Hello,
    I'm designing a game where the player can move through a city composed of 2D image tiles. Right now we have successfully got the pixel collision detection to work on a large single image consisting of an invisible mask image and a visible image that shows a cluster of buildings and objects. The mask overlays the visible buildings and blocks / allows movement based on the color of the mask. Black is a collision, white is open space, etc.
    But this technique won't work for the game, since there will be many cities and vastly larger than this little testbed. I cannot create multiple huge cities into one file - the file would be several megs large, and I'm looking at dozens of cities.
    My idea is to create tiled maps, which will save the coordinates for the various building/object tiles in an XML file. However, I do not know how to make the collision detection work with such a tiled map. Moreover, I don't know if constructing a mosaic city using XML coordinates is the best way to go - I'm open for suggestions. My goal is to simply be able to assemble a city from individual tiles of buildings and masks, and drive/walk my character through the city with pixel collision detection, without using the current setup of a single image and a single mask.
    Any advice/suggestions offered will be GREATLY appreciated! This is our first Java project, but hopefully we can make this work.
    Thank you so much!
    Message was edited by:
    Gateway2007 - clarifying that this is a collision detection based on pixels, not planes or other method.

    Sound like this might be too late of a suggestion, but have you looked at Slick at all?
    http://slick.cokeandcode.com/static.php?page=features
    It might help with the tiling and collision aspects.

  • Trying to get collision detection working with havok

    Hi - I'm having some trouble using collision detection within
    director using a w3d file with havok applied to it. I've been using
    the registerinterest function but I get a "value out of range"
    error.
    This is my code (there is a cone and box on a plane imported
    from 3d max - named Cone01 and Box01 these are both movable rigid
    bodies).
    on beginSprite me
    box1=member("3d").model("Box01")
    cone1=member("3d").model("Cone01")
    w = member ( 1 )
    hk = member( 2 )
    hk.initialize( w, 0.1, 1 )
    hk.registerInterest (box1, cone1, 10, 0, #collision, me)
    end
    on collision me, details
    sound(2).play(member("hihats"))
    end
    on enterFrame me
    end
    I've also tried this and had no luck:
    on beginSprite me
    rb1 = sprite(1).pHavok.rigidBody("Box01")
    rb2 = sprite(1).pHavok.rigidBody("Cone01")
    w = member ( 1 )
    hk = member( 2 )
    hk.initialize( w, 0.1, 1 )
    hk.registerInterest (rb1, rb2, 10, 0, #collision, me)
    end
    Any help would be great.
    Thanks

    quote:
    Originally posted by:
    josiewales
    Hi - I'm having some trouble using collision detection within
    director using a w3d file with havok applied to it.
    Just study this example:
    http://necromanthus.com/Games/ShockWave/tutorials/FPS_Havok.html
    cheers

  • Character rotation problem in tiled map

    Hi I am trying to rotate the character in a tiled map. Its is successful but theres problem with moving diagonally. When i pressed for example up and right keypressed, when its moving it will rotate as i wanted but when i released the buttons, it either rotate to the up or right. I want the image to rotate diagonally and stay as it is when i released the buttons.
    Here are my source code...I noe its very long but really need someone help...There are 3 java files. (Sorry for dis long and ridiculous codes...)
    1) Game.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    public class Game extends Canvas implements KeyListener
         private BufferStrategy strategy;
         private GameMap map=new GameMap();
         private Player player;
         private boolean left,right,up,down;
         Image ship = Toolkit.getDefaultToolkit().getImage("res/up1.PNG");
         public Game()
              Frame frame = new Frame("Pirate Game");
              frame.setLayout(null);
              setBounds(0,30,480,510);
              frame.add(this);
              frame.setSize(480,510);
              frame.setResizable(false);
              // exit the game
              frame.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              frame.addKeyListener(this);
              addKeyListener(this);
              frame.setVisible(true);
              createBufferStrategy(2);
              strategy = getBufferStrategy();
              player = new Player(ship, map, 1.5f, 1.5f);
              // start the game loop
              gameLoop();
    public void gameLoop()
              boolean gameRunning = true;
              long last = System.nanoTime();     
              // keep looking while the game is running
              while (gameRunning)
                   Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
                   // clear the screen
                   g.setColor(Color.black);
                   g.fillRect(0,0,480,480);
                   // render our game objects
                   g.translate(0,0); //placing the map to desired location on the frame
                  map.paint(g);
                   player.paint(g);
                   // flip the buffer so we can see the rendering
                   g.dispose();
                   strategy.show();
                   // pause a bit so that we don't choke the system
                   try { Thread.sleep(4); } catch (Exception e) {};
                   long delta = (System.nanoTime() - last) / 1000000;
                   last = System.nanoTime();
                   for (int i=0;i<delta / 5;i++)
                        logic(5);
                   if ((delta % 5) != 0)
                        logic(delta % 5);
         public void logic(long delta) {
              // check the keyboard and record which way the player
              // is trying to move this loop
              float dx = 0;
              float dy = 0;
              if (left)
                   dx -= 1;
              if (right)
                   dx += 1;
              if (up)
                   dy -= 1;
              if (down)
                   dy += 1;
              // if the player needs to move attempt to move the entity
              // based on the keys multiplied by the amount of time thats
              // passed
              if ((dx != 0) | (dy != 0))
                   player.move(dx * delta * 0.0015f,dy * delta * 0.0015f);
         public void keyTyped(KeyEvent e) {}
         public void keyPressed(KeyEvent e)
              if (e.getKeyCode() == KeyEvent.VK_LEFT)
                   left = true;
              if (e.getKeyCode() == KeyEvent.VK_RIGHT)
                   right = true;
              if (e.getKeyCode() == KeyEvent.VK_DOWN)
                   down = true;
              if (e.getKeyCode() == KeyEvent.VK_UP)
                   up = true;
         public void keyReleased(KeyEvent e)
              if (e.getKeyCode() == KeyEvent.VK_LEFT)
                   left = false;
              if (e.getKeyCode() == KeyEvent.VK_RIGHT)
                   right = false;
              if (e.getKeyCode() == KeyEvent.VK_DOWN)
                   down = false;
              if (e.getKeyCode() == KeyEvent.VK_UP)
                   up = false;
         public static void main(String args[])
          new Game();
    2) GameMap.java
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class GameMap
         int width = 15;
        int height =15;
        static final int TILE_SIZE = 32;
             int[][]  A  =  {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,3,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,2,2,2,2,2,2,2,2,2,2,2,2,2,1},
                                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
        Image sea = Toolkit.getDefaultToolkit().getImage("res/sea.PNG");
        Image rock = Toolkit.getDefaultToolkit().getImage("res/rock.PNG");
         public void paint(Graphics g)
            for(int across = 0; across < width ; across++)
                for(int vert = 0; vert < height ; vert++)
                    if (A[across][vert] == 1)
                    g.drawImage(rock,across*TILE_SIZE,vert*TILE_SIZE,null);
                         else
                         g.drawImage(sea,across*TILE_SIZE,vert*TILE_SIZE,null);
        public boolean blocked(float x, float y)
              return A[(int) x][(int) y] == 1;
    3) Player.java
    import java.awt.Graphics2D;
    import java.awt.Image;
    public class Player {
         private float x;
         private float y;
         private Image image;
         private GameMap map;
         private float ang;
         private float size=0.3f;
         public Player(Image image, GameMap map, float x, float y)
              this.image = image;
              this.map = map;
              this.x = x;
              this.y = y;
         public boolean move(float dx, float dy)
              // new position
              float nx = x + dx;
              float ny = y + dy;
              //check collision
              if (validLocation(nx, ny)) {
                   x = nx;
                   y = ny;
                   // and calculate the angle we're facing based on our last move
                   ang = (float) (Math.atan2(dy, dx) + (Math.PI / 2));
                   return true;
              // if it wasn't a valid move don't do anything apart from tell the caller
              return false;
         public boolean validLocation(float nx, float ny)
              if (map.blocked(nx - size, ny - size))
                   return false;
              if (map.blocked(nx + size, ny - size))
                   return false;
              if (map.blocked(nx - size, ny + size))
                   return false;
              if (map.blocked(nx + size, ny + size))
                   return false;
              return true;
         public void paint(Graphics2D g) {
              int xp = (int) (map.TILE_SIZE * x);
              int yp = (int) (map.TILE_SIZE * y);
              // rotate the sprite based on the current angle and then
              // draw it
              g.rotate(ang, xp, yp);
              g.drawImage(image, (int) (xp - 16), (int) (yp - 16), null);
              g.rotate(-ang, xp, yp);
    }

    rotate() should always be accompanied with appropriate translate().
    See:
    http://java.sun.com/docs/books/tutorial/2d/TOC.html
    http://www.adtmag.com/java/articleold.aspx?id=1241
    http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html
    And, never mix AWT components with Swing ones.
    Use JPanel instead of Canvas.
    Use also standard drawing/painting technique shown above URSs.

  • Better way of collision detection?

    right now I'm experiencing problems with using the same speed
    in reverse for collision detection (such as +=5 being countered by
    -= 5). While this works most of the time, if the velocity of the
    moving object changes, or on occasion, is out of sync with the map,
    the moving object gets stuck like glue to the "wall".
    Is there some other method of stopping the velocity when
    colliding, without freezing the object in place?

    I changed the = manspeed to = manspeed +1 and now the avatar
    is now "moonwalking"???
    for (i=1;i<49;i++){
    the_wall = this["brick_mc"+i];
    if(Key.isDown(Key.LEFT) &&
    avatar_mc.body_mc.hitTest(the_wall)){
    avatar_mc._x += manspeed +1;
    if(Key.isDown(Key.RIGHT) &&
    avatar_mc.body_mc.hitTest(the_wall)){
    avatar_mc._x -= manspeed +1;
    if(Key.isDown(Key.DOWN) &&
    avatar_mc.body_mc.hitTest(the_wall)){
    avatar_mc._y -= manspeed +1;
    if(Key.isDown(Key.UP) &&
    avatar_mc.body_mc.hitTest(the_wall)){
    avatar_mc._y += manspeed +1;
    }

  • Collisions detection in 3D environments

    Hi, all.
    Has anyone worked with collisions detection in 3D environments?
    I want to create an application in LabView for detecting collisions between 3D objects. I'm working with VRML models and the 3D Picture Control, but I'm open to other posibilities, if they are possible to be integrated into Labview.
    Thanks in advance.
    Regards,
    Francisco

    You may want to check out the new digital
    prototyping tools that just released. It is called the NI SoftMotion Module for SolidWorks and works with SolidWorks 2009 Service Pack 2.1 or higher and LabVIEW 2009 or higher. These tools connect accurate
    mechanical/physics simulation capabilities in SolidWorks with
    industrial-grade motion control software in LabVIEW. There are two ways you can perform collision detection using the tools:
    1. After the your motion control application is finished running, switch the scan engine to configuration mode. (To do this, right-click on My Computer >Utilities>Scan Engine Mode.) Then, in the SolidWorks motion study Motion Manager Toolbar, right-click on the top item in the tree (which has the same name as your assembly) and select Check Interference. Then click on the parts you want to check for collisions on, and select Find Now. If collisions occured, SolidWorks will tell you the time of the collisions and the volume of overlap.
    or 
    2. You can use a distance sensor to detect collisions. In this case, LabVIEW can monitor the sensor while the motion simulation is running and take action (such as stopping the move and alerting you) if the sensor value changes.  This also enables to to detect a "near miss" where the parts came too close for comfort but didn't actually collide. To include
    proximity sensor feedback in your LabVIEW control applications, add a
    dimension to your SolidWorks assembly and connecting it to a Measurement sensor in SolidWorks with an Alert configured
    (for example, alert if the distance is less than 5 mm). Then in
    LabVIEW, right-click on the SolidWorks assembly item in the LabVIEW
    project and select Map Sensors. For an example, launch the LabVIEW Example Finder (Help>Find Examples) and try running the shipping example called "Basic SolidWorks Sensors.lvproj".
    Here's some background information...
    NI
    SoftMotion for SolidWorks enables mechanical, electrical and control
    engineers to collaborate by creating a digital prototype of the motion
    control system that integrates mechanical simulation, motion control
    software, and sensor feedback. As soon as you have a CAD drawing, you
    can begin prototyping the machine design long before you incur the
    expense of building a physical machine. The new tools enable you to do
    thinks like:
    visualize realistic machine operation
    validate and iterate on the mechanical, control and electrical aspects of your design
    estimate the cycle time performance
    check for collisions or other programming mistakes
    calculate force/torque loads for stress analysis 
    select and size motor and mechanical transmission components
    improve communication between the engineers on your team and with customers
    deploy the validated motion control application to NI CompactRIO for use on the physical machine
    The following software versions are required:
    • LabVIEW 2009 (32-bit) or later
    • LabVIEW NI SoftMotion Module Standard or Premium
    • SolidWorks 2009 Service Pack 2.1 or later and SolidWorks Motion Simulation with the Motion Simulation add-in enabled from the Tools menu
    in SolidWorks. This is included with SolidWorks Premium, Simulation
    Premium, or Simulation Professional. When you enable the Motion
    Simulation add-in from the Add-Ins dialog box in SolidWorks,
    place a checkmark in both the left and right checkboxes so you don’t
    have to reenable the add-in each time you use NI SoftMotion for
    SolidWorks.
    For more information, visit this site:
    http://www.ni.com/digitalprototyping/
    Here's a few other resources to get you started. 
    LabVIEW-SolidWorks Digital Prototyping Training (see the topic called "Motion Control Timing and Sequencing")
    Getting Started Guide for NI SoftMotion for SolidWorks
    Here are links to the evaluation versions of LabVIEW and the NI SoftMotion Module for SolidWorks:
    LabVIEW 2009
    NI SoftMotion Module (includes a 30 day evaluation license for NI SoftMotion for SolidWorks)
    Contact your local SolidWorks reseller to purchase SolidWorks, upgrade your existing SolidWorks installation to SolidWorks Premium (which includes the required SolidWorks Motion Simulation capability), or to request an evaluation version of SolidWorks:
    http://www.solidworks.com/sw/contact.htm
    For information on deploying your motion control application to the NI CompactRIO programmable automation controller (PAC) platform, see this site:
    http://www.ni.com/motion/

  • Events Triggered By Collision Detection In Shockwave 3D Environment Happen More Than Once?

    Okay, I've finally managed to get my Director 3D game to move an object to a new random position when collision detection occurs with that object! HOWEVER, sometimes it will work as expected and other times the object seems to move SEVERAL times before settling. Anyone have any idea why it isn't always just moving once and settling as I'd hoped it would...?
    To see an example of the problem I'm facing, create a new Director movie then insert a new Shockwave 3D media element into that Director movie named "Scene" and apply the below code to that 3D media element. I've tried to trim the code down as much as possible to get right to the heart of the problem:
    =====
    property Scene  -- reference to 3D cast member
    property pSprite    -- referebce to the 3D sprite
    property pCharacter -- reference to the yellow in the 3D world
    property pTransformgreen01Flag -- reference to the flag which will trigger action to move green01 + increase score on collision
    property pTransformgreen02Flag -- reference to the flag which will trigger action to move green02 + increase score on collision
    on beginSprite me
      -- initiate properties and 3D world
      pSprite = sprite(me.spriteNum)
      Global Scene
      Scene = sprite(me.spriteNum).member
      Scene.resetWorld()
      Tempobjres = Scene.newmodelresource("sphereRES", #sphere)  --create sphere modelresource
      Tempobjres.radius = 10     --set sphere modelresrource radius to 20
      Tempobjres.resolution = 17   --set the sphere modelresource resolution to 17
      Tempobj = scene.newmodel("yellow", tempobjres)   --create a model from the sphere modelresource
      Tempshader = scene.newshader("sphereshd", #standard)   --create a new standard shader
      Tempshader.diffuse = rgb(250,250,10)   --set the diffuse color (in this case, a light green)
      Tempshader.texture = void   --set the texture of the shader to void
      Tempobj.transform.position=vector(0,0,0)
      Tempobj.shaderlist = tempshader   -- assign the shader to the model
      Tempobjres1 = Scene.newmodelresource("sphereRES1", #sphere)  --create sphere modelresource
      Tempobjres1.radius = 10     --set sphere modelresrource radius to 20
      Tempobjres1.resolution = 17   --set the sphere modelresource resolution to 17
      Tempobj1 = scene.newmodel("green01", tempobjres1)   --create a model from the sphere modelresource
      Tempshader1 = scene.newshader("sphereshd1", #standard)   --create a new standard shader
      Tempshader1.diffuse = rgb(100,200,50)   --set the diffuse color (in this case, a light green)
      Tempshader1.texture = void   --set the texture of the shader to void
      Tempobj1.transform.position = vector(25,25,0)
      Tempobj1.shaderlist = tempshader1   -- assign the shader to the model
      Tempobjres2 = Scene.newmodelresource("sphereRES2", #sphere)  --create sphere modelresource
      Tempobjres2.radius = 10     --set sphere modelresrource radius to 20
      Tempobjres2.resolution = 17   --set the sphere modelresource resolution to 17
      Tempobj2 = scene.newmodel("green02", tempobjres2)   --create a model from the sphere modelresource
      Tempshader2 = scene.newshader("sphereshd2", #standard)   --create a new standard shader
      Tempshader2.diffuse = rgb(100,200,50)   --set the diffuse color (in this case, a light green)
      Tempshader2.texture = void   --set the texture of the shader to void
      Tempobj2.transform.position = vector(-25,-25,0)
      Tempobj2.shaderlist = tempshader2   -- assign the shader to the model
      --the following lines will add collision detection for all three on-screen 3D objects
      Tempobj.addModifier(#collision)
      Tempobj.collision.enabled=true
      Tempobj1.addModifier(#collision)
      Tempobj1.collision.enabled=true
      Tempobj2.addModifier(#collision)
      Tempobj2.collision.enabled=true
      Tempobj.collision.resolve=true
      Tempobj1.collision.resolve=true
      Tempobj2.collision.resolve=true
      --the following lines will tell Director what to do with a specific object when it collides with another
      Tempobj.collision.setCollisionCallBack(#beepsound, me)
      Tempobj1.collision.setCollisionCallBack(#hitgreen01, me)
      Tempobj2.collision.setCollisionCallBack(#hitgreen02, me)
      pCharacter = Scene.model("yellow")
      -- we must define pCharacter after we use the resetWorld() command
      -- otherwise this variable object will be deleted
      createCollisionDetect
      pTransformgreen01Flag = false
      pTransformgreen02Flag = false
    end
    on createCollisionDetect
      Global Scene
      -- add collision modifier to the character
      pCharacter.addmodifier(#collision)
      -- set bounding geometry for collision detection to bounding box of model
      pCharacter.collision.mode = #mesh
      -- resolve collision for character
      pCharacter.collision.resolve = TRUE
    end
    on keyDown
      Global Scene
      case(chartonum(the keypressed)) of
        30: --up arrow
          scene.model("yellow").translate(0,5,0)
        31: --down arrow
          scene.model("yellow").translate(0,-5,0)
        28: --left arrow
          scene.model("yellow").translate(-5,0,0)
        29: --right arrow
          scene.model("yellow").translate(5,0,0)
      end case
    end
    --when "yellow" (player character) hits another object, this will happen:
    on beepsound me, colData
      beep --plays sound
    end
    --when "green01" is hit by another object, this will happen:
    on hitgreen01 me, colData
      Global Scene
      pTransformgreen01Flag=true
    end
    --when "green02" is hit by another object, this will happen:
    on hitgreen02 me, colData
      Global Scene
      pTransformgreen02Flag=true 
    end
    on enterFrame me
      Global Scene
      if pTransformgreen01Flag then
        --the following lines will generate new random x and y co-ordinates for green01
        randomx=random(-110,110)
        green01x=randomx
        randomy=random(-90,90)
        green01y=randomy
        Scene = member("Scene")
        Scene.model("green01").transform.position = vector(green01x,green01y,0)
        pTransformgreen01Flag = false
      end if
      if pTransformgreen02Flag then
        --the following lines will generate new random x and y co-ordinates for green02
        randomx=random(-110,110)
        green02x=randomx
        randomy=random(-90,90)
        green02y=randomy
        Scene = member("Scene")
        Scene.model("green02").transform.position = vector(green02x,green02y,0)
        pTransformgreen02Flag = false
      end if
    end
    =====
    I imagine the part that's causing the issue is the "on enterFrame me" part at the end, but can't see any reason why it wouldn't just perform the desired action ONCE every time...?
    This is really confusing the hell out of me and is pretty much the final hurdle before I can call my game "finished" so any and all assistance would be GREATLY appreciated!

    You can get yourself a used copy of my book http://www.amazon.com/Director-Shockwave-Studio-Developers-Guide/dp/0072132655/ for $0.82 + shipping.  Chapter 14 contains 33 pages which deal specifically with the vagaries of the collision modifier.
    You can download just the chapter on Collision Detection from http://nonlinear.openspark.com/book/Collisions.zip.  This includes the demo movies and the unedited draft of the text for the chapter.
    Perhaps you will find this useful.

  • Camera Collision Detection - Is It Possible?

    Hi,
    I am making a 3D RPG game and I would like to know if it is possible to get collision detection on a camera created in Adobe Director 11.  I have my 3D character running through an underground maze and he detects correctly on the walls of the maze.  However, I also have a camera as a child to the character so this moves with him.  I have added a bounding-box to this camera but it still doesn't detect whereas the gunBB works fine, as does the characterBB.
    This is really confusing and I don't know what I am doing wrong.  Any help would be really appreciated!
    Thanks, Phil.

    Thanks for the reply.  It is not exactly what I am looking for as the script is different than the style I am using.  This is the script I have got so far, I have also added an extra camera to view what is happening.
    property pSprite, p3Dmember -- reference to the 3D member
    --property pLevel, maze -- Level
    --property pLeftArrow, pRightArrow, pDownArrow, pUpArrow -- arrow keys
    --property pCharacter -- character in the 3D world
    --property pTofuBB, pGunBB, gun --  character + gun
    --property gUseGun, hasGun
    --property pCamera, pCameraBoundingBox --camera and bounding box
    --property barrier,mountains,exitmaze
    --property door1, door2, turret, turretgun
    --property keylist, keypresslist -- for keys pressed
    --on beginSprite me
    --  -- define the 3D cast member
    --  p3Dmember = sprite(me.spriteNum).member
    --  -- reset the 3D world
    --  p3Dmember.resetWorld()
    --  pSprite = sprite(me.spriteNum)
    --  pCamera = pSprite.camera
    --  -- define level as 3DS level Plane - must all be defined after resetWorld()
    --  pLevel = p3Dmember.model("landscape")
    --  mountains = p3Dmember.model("mountains")
    --  turret = p3Dmember.model("turret")
    --  turretgun = p3Dmember.model("turretgun")
    --  maze = p3Dmember.model("maze")
    --  exitmaze = p3Dmember.model("exitmaze")
    --  pCharacter = p3Dmember.model("hero")
    --  gun = p3Dmember.model("gun")
    --  barrier = p3Dmember.model("barrier")
    --  door1 = p3Dmember.model("door1")
    --  door2 = p3Dmember.model("door2")
    --  -- stop hero walking biped animation
    --  pCharacter.bonesPlayer.pause()
    --  -- below for key control
    --  keylist = []
    --  keypresslist = []
    --  -- this sets up a list of keycodes to track.
    --  -- this code covers the arrow keys only, it could be changed to cover a full range of keys
    --  repeat with i = 123 to 126
    --    keylist[i] = i -- this creates a list of keycodes to track
    --    keypresslist[i] = 0 -- this creates a "last state" list that corresponds to the keycode.
    --    --keypresslist tracks the last known state of that key, so we can tell when a keypress has changed.
    --  end repeat
    --  -- key control end
    --  createBoundingBoxes
    --  createLight
    --end
    -- code used to create bounding boxes
    --on createBoundingBoxes
    --  -- create tofu bounding box for character
    --  tofuBB_MR = p3Dmember.newModelResource("tofuBox",#box)
    --  tofuBB_MR.height = 235
    --  tofuBB_MR.width = 235
    --  tofuBB_MR.length = 500
    --  pTofuBB = p3Dmember.newModel("tofuBox",tofuBB_MR)
    --  pTofuBB.worldPosition = pCharacter.worldPosition
    --  -- create parent child relationships
    --  pCharacter.addChild(pTofuBB, #preserveWorld)
    --  invisShader = p3Dmember.newShader("invisShader",#standard)
    --  invisShader.transparent = TRUE
    --  invisShader.blend = 50
    --  pTofuBB.shaderlist = p3Dmember.shader("invisShader")
    --  pCamera = p3Dmember.newCamera("camera")
    --  frontCam = p3Dmember.newCamera("frontCam")
    --  frontCam.fieldOfView = 35
    --  frontCam.transform.position = vector(-14150,-3100,-600)
    --  frontCam.transform.rotation = vector(90,0,180)
    --  pSprite.camera = p3Dmember.camera("frontCam")
    --  pCamera.fieldOfView = 75
    --  pCamera.transform.position = vector(500,1800,450) --450
    --  pCamera.transform.rotation = vector(90,0,180)
    --  pSprite.camera = p3Dmember.camera("camera")
    --  cameraModRes = p3Dmember.newModelResource("cameraModRes",#sphere)
    --  cameraModRes.radius = 200
    --  pCameraBoundingBox = p3Dmember.newModel("CameraBoundingBox",cameraModRes)
    --  pCameraBoundingBox.worldPosition = pCamera.worldPosition
    --  pCameraBoundingBox.shaderList = p3Dmember.shader("invisShader")
    --  pCamera.addChild(pCameraBoundingBox, #preserveWorld)
    --  pCharacter.addChild(pCamera,#preserveWorld)
    --  -- create gun bounding box
    --  gun.worldposition.z = gun.worldposition.z + 200
    --  gunMR = p3Dmember.newModelResource("gunSphere",#sphere)
    --  gunMR.radius = 218
    --  pGunBB = p3Dmember.newModel("gunSphere", gunMR)
    --  pGunBB.worldPosition = gun.worldPosition
    --  pGunBB.shaderList = p3Dmember.shader("invisShader")
    --  pGunBB.addChild(gun, #preserveWorld)
    --end
    -- code below used to light up level
    --on createLight
    --  -- create a point 'bulb' type light
    --  p3Dmember.newLight("Bulb Light", #point )
    --  -- position the light
    --  p3Dmember.light("Bulb Light").transform.position = vector(0,0,100)
    --  -- define light color and intensity
    --  p3Dmember.light("Bulb Light").color = rgb(255,255,255)
    --  -- Make the character model a parent of the light
    --  -- Bulb Light becomes a child of pCharacter
    --  -- This is done so that the light will always move
    --  -- with the character.
    --  pCharacter.addChild(p3Dmember.light("Bulb Light"),#preserveParent)
    --end
    --on keyUp me
    --  --pCharacter.bonesPlayer.pause()
    --  --if keypressed("s")
    --end
    --on keydown me
    --  if keypressed("c") then changeCamera
    --end
    --on changeCamera
    --  -- check the sprites camera and switch
    --  if pSprite.camera = p3Dmember.camera("frontCam") then
    --     pSprite.camera = p3Dmember.camera("camera")
    --     else
    --     pSprite.camera = p3Dmember.camera("frontcam")
    --     end if
    --end
    --on exitFrame me
    -- below detects which keys are pressed
    --repeat with i = 1 to keylist.count
    --inewstate= keypressed( keylist[i] )
    --if keypresslist[i] <> inewstate then -- this means the key changed status from whether it's up or down
    --if inewstate= 0 then
    -- they key was released
    --keyLastReleased = keylist[i]
    --if (keyLastReleased=123) then pLeftArrow = 0 -- 123 = left arrow key
    --if (keyLastReleased=124) then pRightArrow = 0 -- 124 = right arrow key
    --if (keyLastReleased=125) then
    --pDownArrow = 0 -- 125 = down arrow key
    --pCharacter.bonesPlayer.pause()
    --end if
    --if (keyLastReleased=126) then
    --pUpArrow = 0 -- 126 = up arrow key
    --pCharacter.bonesPlayer.pause()
    --end if
    --else
    -- the key was pressed
    --keyLastPressed = keylist[i]
    --if (keyLastPressed=123) then pLeftArrow = 1 -- 123 = left arrow key
    --if (keyLastPressed=124) then pRightArrow = 1 -- 124 = right arrow key
    --if (keyLastPressed=125) then pDownArrow = 1 -- 125 = down arrow key
    --if (keyLastPressed=126) then pUpArrow = 1 -- 126 = up arrow key
    --end if
    --keypresslist[i] = inewstate-- update so we remember its new state.
    --end if
    --end repeat
    -- by the time this repeat loop has finished, keypresslist will contain a complete index of what keys
    -- are held down, and which aren't.
    -- Note: most keyboards have a limit on how many keys they'll track simultaneously.
    --checkCollisions
    --characterMove
    -- gun collision start
    --if gUseGun = TRUE then
    --pTofuBB.addChild(pGunBB,#preserveParent)
    --pGunBB.worldPosition = pTofuBB.worldPosition
    --pGunBB.worldPosition.z = 500
    --pGunBB.worldPosition.x = pCharacter.worldPosition.x - 150 --50
    ---pGunBB.worldPosition.y = -860
    --pGunBB.rotate(0,0,-240)
    --pCharacter.bonesPlayer.pause()
    --gUseGun = FALSE
    --hasGun = TRUE
    --end if
    -- gun collision end
    --end
    --on characterMove
    -- if the right arrow is pressed,
    -- rotate the character 5 degrees about the z-axis
    --if pRightArrow then
    -- rotate character and camera
    --pCharacter.rotate(0,0,-2)
    --end if
    --if the left arrow is pressed,
    -- rotate character -5 degrees about the z-axis
    --if pLeftArrow then
    --pCharacter.rotate(0,0,2)
    --end if
    -- if the up arrow is pressed,
    -- move the character 5 pixels along the y-axis
    --if pUpArrow then
    --if (pcharacter.bonesPlayer.playing = 0) then
    --pCharacter.bonesplayer.loop = true
    --if (_key.shiftDown) then
    --pCharacter.bonesPlayer.playRate = 2
    --if (hasGun = TRUE) then -- running
    --pCharacter.bonesplayer.play("hero", 1, 6270, 8330, 1)
    --else
    --pCharacter.bonesplayer.play("hero", 1, 2067, 4130, 1)
    --end if
    --else
    --pCharacter.bonesPlayer.playRate = 1
    --if (hasGun = TRUE) then -- walking
    --pCharacter.bonesplayer.play("hero", 1, 4200, 6200, 1)
    --else
    --pCharacter.bonesplayer.play("hero", 1, 0, 2000, 1)
    --end if
    --end if
    --end if -- bonesPlayer playing
    --if (_key.shiftDown) then
    --pCharacter.translate(120,0,0)
    --else
    --pCharacter.translate(50,0,0)
    --end if
    --end if
    -- if the down arrow is pressed,
    -- move the character -5 pixels along the y-axis
    --if pDownArrow then
    --if (pcharacter.bonesPlayer.playing = 0) then
    --pCharacter.bonesplayer.loop = true
    --if (_key.shiftDown) then
    --pCharacter.bonesPlayer.playRate = 2
    --if (hasGun = TRUE) then -- running
    --pCharacter.bonesplayer.play("hero", 1, 6270, 8330, 1)
    --else
    --pCharacter.bonesplayer.play("hero", 1, 2067, 4130, 1)
    --end if
    --else
    --pCharacter.bonesPlayer.playRate = 1
    --if (hasGun = TRUE) then -- walking
    --pCharacter.bonesplayer.play("hero", 1, 4200, 6200, 1)
    --else
    --pCharacter.bonesplayer.play("hero", 1, 0, 2000, 1)
    --end if
    --end if
    --end if -- bonesPlayer playing
    --if (_key.shiftDown) then
    --pCharacter.translate(-120,0,0)
    --else
    --pCharacter.translate(-50,0,0)
    --end if
    --end if
    -- floor collision
    --thisPosn = pTofuBB.worldPosition
    -----thisPosn.z = 1000
    --tModelList = [pLevel, maze, door1, door2] -- removed wall as its no longer on level
    --tOptionsList = [#levelOfDetail: #detailed, #modelList: tModelList]
    --thisData = p3Dmember.modelsUnderRay(thisPosn,vector(0,0,-1),tOptionsList)
    --if thisData.count then
    --totalCount = thisData.count
    --repeat with dataIndex = 1 to totalCount
    --terrainPosn = thisData[dataIndex].isectPosition
    --- if (thisData[dataIndex].model = pLevel) then
    --tDiff = (terrainPosn.z - pTofuBB.worldPosition.z) + 375
    --pCharacter.translate(0,0,tDiff,#world)
    --exit repeat
    --end repeat
    --end if
    --end
    --on checkCollisions
    --tModelList = [pGunBB, barrier, mountains, maze, exitmaze, turret, turretgun]
    --tOptionsList = [#maxNumberOfModels: 2, #levelOfDetail: #detailed, #modelList: tModelList, #maxDistance: 300]
    -- make 4 rays around character checking for collisions, 90 degrees apart
    --repeat with i = 1 to 18
    --pCharacter.rotate(0,0,20,#self)
    --returnData = p3Dmember.modelsUnderRay(pCharacter.worldPosition,pCharacter.transform.xAxis,tOptionsList )
    --if (returnData.count) then
    -- first in array is closest
    --checkObjectFoundDistance(returnData[1])
    --end if
    --end repeat
    --end
    --on checkObjectFoundDistance thisData -- check distance from collision with objects
    --dist = thisData.distance
    -- check if distance is less than width of bounding box
    --if (dist < 150) then
    --case thisData[#model].name of
    --"gunSphere":
    --gUseGun = TRUE
    --"barrier":
    -- get distance of penetration
    --diff = 150 - dist
    -- calculate vector perpend icular to the wall's surface to move the character
    -- using the #isectNormal property
    --tVector = thisData.isectNormal * diff
    -- move the character in order to resolve the collision
    --pCharacter.translate(tVector,#world)
    --end case
    --end if
    --if (dist < 150) then
    --case thisData[#model].name of
    --"gunSphere":
    --gUseGun = TRUE
    --"mountains":
    -- get distance of penetration
    --diff = 150 - dist
    -- calculate vector perpend icular to the wall's surface to move the character
    -- using the #isectNormal property
    --tVector = thisData.isectNormal * diff
    -- move the character in order to resolve the collision
    --pCharacter.translate(tVector,#world)
    --end case
    --end if
    --if (dist < 150) then
    --case thisData[#model].name of
    --"gunSphere":
    --gUseGun = TRUE
    --"maze":
    -- get distance of penetration
    --diff = 150 - dist
    -- calculate vector perpend icular to the wall's surface to move the character
    -- using the #isectNormal property
    --tVector = thisData.isectNormal * diff
    -- move the character in order to resolve the collision
    --pCharacter.translate(tVector,#world)
    --end case
    --end if
    --if (dist < 150) then
    --case thisData[#model].name of
    --"gunSphere":
    --gUseGun = TRUE
    --"exitmaze":
    -- get distance of penetration
    --diff = 150 - dist
    -- calculate vector perpend icular to the wall's surface to move the character
    -- using the #isectNormal property
    --tVector = thisData.isectNormal * diff
    -- move the character in order to resolve the collision
    --pCharacter.translate(tVector,#world)
    --end case
    --end if
    --if (dist < 150) then
    --case thisData[#model].name of
    --"gunSphere":
    --gUseGun = TRUE
    --"turret":
    -- get distance of penetration
    --diff = 150 - dist
    -- calculate vector perpend icular to the wall's surface to move the character
    -- using the #isectNormal property
    --tVector = thisData.isectNormal * diff
    -- move the character in order to resolve the collision
    --pCharacter.translate(tVector,#world)
    --end case
    --end if
    --if (dist < 150) then
    --case thisData[#model].name of
    --"gunSphere":
    --gUseGun = TRUE
    --"turretgun":
    -- get distance of penetration
    --diff = 150 - dist
    -- calculate vector perpend icular to the wall's surface to move the character
    -- using the #isectNormal property
    --tVector = thisData.isectNormal * diff
    -- move the character in order to resolve the collision
    --pCharacter.translate(tVector,#world)
    --end case
    --end if
    --end

Maybe you are looking for