Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 15 Sep 2003
Offline Last Active Mar 19 2016 11:04 AM

Topics I've Started

Figuring out where a projectile will go

07 March 2016 - 02:16 PM

I have an old school space game during a game jam and want to turn it into a full game, only issue I'm having is making an AI that can A) Hit things accurately and B) realize when projectiles are coming towards them and avoid them. What makes it difficult is the projectiles have wonky paths because they're affected by a crude approximation of gravity:
Now how the projectiles move is the star in this picture has a component called Gravity Source on it, and it supplies the force calculations:
using UnityEngine;
using System.Collections;
public class GravitySource : MonoBehaviour
    public Vector3 ForceAtPoint(Vector3 xyz)
        var newForce = transform.position - xyz;
        if (newForce.sqrMagnitude > 0.0f)
            newForce = (newForce / newForce.sqrMagnitude) * 5000.0f;
        return newForce;
and the missiles & player have a Gravity Receiver, the missiles having a 10x multiplier and players 1x

using UnityEngine;
using System.Collections;
public class GravityReciever : MonoBehaviour {
    public float gravityMultiplier = 1.0f;
    public GravitySource gravitySource;
    Rigidbody rb;
    void Start()
        rb = GetComponent<Rigidbody>();
void FixedUpdate () {
        rb.AddForce(gravitySource.ForceAtPoint(transform.position) * Time.fixedDeltaTime * gravityMultiplier, ForceMode.Acceleration);

Now my question is, how do I calculate where a projectile is going so I can have my AI make decent shots as well as dodging incoming fire?
 https://dl.dropboxusercontent.com/u/168938/Games/Space%20Melee/OrbitProjectileExample.zip (a copy of the physics code with all the assets removed to play around with/make examples)

RIP Torque and Gamebryo

11 November 2010 - 08:45 AM

Emergent Technologies to Liquidate Assets
Instant Action winding down operations

Could kind of see why both of these are going down, Bethesda was a big customer for Gamebryo, but since the Id Buyout I don't see them buying out a company then not using the engine, and I can't really think of many other companies that were big customers for Gamebryo

As for Torque, the time I thought it was done was when Unity launched for windows and my Unity proficiency surpassed my Torque proficiency during the trial of Unity, whereas I had several months in Torque and instead of them pushing to make Torque easier to understand/use they went forward with creating more SKU's instead.

Weird to see 2 engines go so close together though

Separating Axis Problem(not working on non-AABB)

04 November 2009 - 10:06 AM

I have 2 collision poly's as defined as such:
	import flash.geom.Point;
	public class CollisionPoly
		public var points:Array;
		public var edges:Array;
		public function CollisionPoly(vertexes:Array):void
			this.points = vertexes;
			this.edges = new Array();
			for(var i:Number = 0; i < points.length; i++)
				var p:Point = points[i];
				var nextPoint:Point = points[(i + 1) % points.length];
				edges[edges.length] = p.subtract(nextPoint);
		public function projectToAxis(axis:Point):Projection
			var min:Number = int.MAX_VALUE;
			var max:Number = -int.MAX_VALUE;
			for(var i:Number = 0; i < points.length; i++)
				var p:Point = points[i];
				var dotProduct:Number = (p.x * axis.x) + (p.y * axis.y);
				if(dotProduct < min)
					min = dotProduct;
				if(dotProduct > max)
					max = dotProduct;
			return new Projection(min,max);
		public function intersects(c:CollisionPoly):Boolean
			var allEdges:Array = new Array();
			for(var i:Number = 0; i < edges.length; i++)
				allEdges[i] = edges[i];
			for(var j:Number = 0; j < c.edges.length; j++)
				allEdges[j + i] = c.edges[j];
			for(i = 0; i < allEdges.length; i++)
				var edge:Point = allEdges[i];
				var axis:Point = edge.clone();
				//Make perpendicular
				var tempx:Number = -axis.y;
				axis.y = axis.x;
				axis.y = tempx;
				var projection:Projection = projectToAxis(axis);
				var cProjection:Projection = c.projectToAxis(axis);
					return false;
			return true;

I have 2 collision poly's for isometric diamonds that this code is incorrectly identifying as intersecting

the first poly is at [[84,0],[124,20],[84,40],[44,20]]
and the second is at [[40,25],[80,45],[40,65],[0,45]]

as shown in this picture it's showing as colliding when it's not

I've stepped through the code and I can't find where in the intersects function it's going wrong, so I'm crying halp here

link to the demo if it helps(click & drag the shapes)

[java] Converting wav's to mp3's

29 September 2009 - 07:55 AM

I'm trying to make a tool to convert wav's to mp3's then send out a notification when it's done. (The wav's will always be 44100Hz 16-bit Stereo files) My first attempt was to link to JMF then attempt to do this:
	public void wavToMP3(String waveFileName, String mp3FileName) throws Exception
		File file = new File(waveFileName);
		AudioInputStream in = AudioSystem.getAudioInputStream(file);
		AudioInputStream out;
		AudioFormat.Encoding encodedFormat = new AudioFormat.Encoding(javax.media.format.AudioFormat.MPEGLAYER3);
		out = AudioSystem.getAudioInputStream(encodedFormat, in);
		File outfile = new File(mp3FileName);
		AudioSystem.write(out, new AudioFileFormat.Type("MP3","mp3"), outfile);

but that results in this error: Exception in thread "main" java.lang.IllegalArgumentException: Unsupported conversion: mpeglayer3 from PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian I can't seem to find what I need to change to fix this, any suggestions?

[java] Java equivelant to AS3's sound.extract()?

31 August 2009 - 10:48 AM

I'm trying to port some Actionscript code to Java, and I'm looking for a way to get an array of frequencies in a format where it's 1 float per sample per channel and there's 2 channels from an mp3 file. Anyone have an example available on how to accomplish this?