Posts tagged Math
Using Ray Casting with Shapes
Feb 15th
Back in July, we looked at how to use Ray Casting for collision detection. We also learned how to use the Separation of Axis Theorem. I recently had a request for a way to use the Shapes we created here with the Ray Casting method. First, lets do a quick review of the shape classes.
The SAT Shape ClassesThe BaseShape class is the class that all shapes extend. It has the basic properties, position, rotation and scale as well as the transform matrix that transforms the vertices based on rotation, scale and position. It has getters and setters for each of those More >
Detecting Collisions with SAT
Nov 28th
Today we will finally be detecting a collision with SAT. We know how SAT works, we’ve built classes to work with SAT, now we can use all of this to detect a real, live collision!
Using the classes we created last time, this is quite simple. First create a shape:
var shape1:Polygon = Polygon.rectangle(530, 30, new Vector2D(270, 360));
It’s a simple polygon created using the static function of the rectangle class. Now we need another shape to collide with:
var shape2:Polygon = Polygon.rectangle(20, 50, new Vector2D(260, 350));
And now we need to test for a collision:
var data:CollisionData = Collision.testShapes(shape1, shape2);
When you run this, you should More >
Using the Separation of Axis Theorem
Nov 22nd
A few months ago, I posted on the separation of axis theorem. You can learn all about SAT and how it works here. What that post failed to do was use the SAT. We will explore using SAT for collision detection in this post.
In the post on SAT, we created the code to detect collisions, however use of the code was not covered. (A download of all the classes used in the post is available at the bottom).
The Shape ClassesThe easiest way to use SAT uses Shape classes. There are two shape classes we will need, the Circle and the More >
A* and Pathfollowing Steering Behavior
Nov 10th
Vehicle Following the Path
In the last three posts, we explored the how A* works, then we put A-star into code, then we looked at different heuristics for A*. Now we will combine A* pathfinding with the path following steering behavior.
We have already done most of the work to do this. But we’ll do a quick review in case you missed those posts.
A* PathfindingIn A* we take a grid of cells and find a path from start to finish. Each cell has an x,y for location, a parent for creating the path, and F, G, and H values for calculating the More >
Steering Behaviors: Leader Following
Oct 29th
The next post steering behaviors series is unaligned collision avoidance. We will be using the Vector2D.as and Vehicle.as classes for this. You will need these classes for the this post. This post is based on Craig Reynold’s article Steering Behaviors For Autonomous Characters.
Leader Following Click to watch
Leader Following is a steering behavior where vehicles follow one leader. Once a leader is chosen, all the other vehicles follow the leader. The followers want to be near the leader but not too close that the leader is covered in vehicles and without getting in his way. Also, the followers want to avoid running into each More >
Steering Behaviors: Flocking
Oct 8th
Flocking, click to watch
The next post steering behaviors series is unaligned collision avoidance. We will be using the Vector2D.as and Vehicle.as classes for this. You will need these classes for the this post. This post is based on Craig Reynold’s article Steering Behaviors For Autonomous Characters.
Flocking is created by combining several steering behaviors: Separation, Cohesion and Alignment.
Separation
Separation is similar to Unaligned Collision Avoidance. This behavior keeps the vehicles a certain distance away from others. This keeps the vehicles from colliding and crowding to close together.
To calculate separation, check each vehicle against the other More >
Steering Behaviors: Unaligned Collision Avoidance
Jul 23rd
The next post steering behaviors series is unaligned collision avoidance. We will be using the Vector2D.as and Vehicle.as classes for this. You will need these classes for the this post. This post is based on Craig Reynold’s article Steering Behaviors For Autonomous Characters.
Unaligned Collision Avoidance, click to watch.
Unaligned Collision Avoidance tries to keep vehicles from colliding with each other. Think of a crowded city. There are a lot of people moving around, but no one runs into someone else. If a person detects a approaching collision, he will steer away from the potential More >
Steering Behaviors: Flow Field Following
Jul 15th
Next up in the steering behaviors series is flow field following. Once again, we will be using the Vector2D.as and Vehicle.as classes for this. If you don’t have them, you should get them because you will need them. This post is based on Craig Reynold’s article Steering Behaviors For Autonomous Characters.
Flow Field, click to watch.
Using a flow field (also called a force field or a vector field) can be very useful. A level designer (or level editor, if you make one) can easily create a flow field by drawing arrows onto the screen. More >
Steering Behaviors: Path Following
Jul 14th
In the last post in the steering behaviors series, we looked at obstacle avoidance. This time we will explore path following. We will be using the Vector2D.as and Vehicle.as classes for this. If you don’t have them, you should get them. This post is based on Craig Reynold’s article Steering Behaviors For Autonomous Characters.
Path Following, click to watch
Path following is used to simulate natural movement through a path. It is different from a train because a train is stuck on the track. The vehicle following these paths are free to move about More >
Steering Behaviors: Obstacle Avoidance
Jul 13th
Avoiding Obstacles, Click to watch.
The next post in the steering behaviors series is obstacle avoidance. We will be using the Vector2D.as and Vehicle.as files for this. If you don’t have them, you should get them. This behavior is based on Craig Reynold’s article Steering Behaviors For Autonomous Characters.
Obstacle Avoidance is used in order to have a vehicle move around an environment without running into objects. This is different from fleeing in one main way. If the vehicle is near a circle and it is not going to hit the circle, nothing is More >






