Jump to content

  • Log In with Google      Sign In   
  • Create Account


PhilObyte

Member Since 26 Jul 2012
Offline Last Active Yesterday, 02:55 PM

Topics I've Started

2D chase steering algorithm

30 May 2014 - 04:52 PM

Hello community,

I do not know how to make enemies chase the player.

I already have the code to find the angle the enemy needs to shoot at

to hit the moving player, and how to steer to it.

(I don't want to make them cheat, they need to use their left-/right-jets like the player).

But how do I find out which translational acceleration needs to be applied?

 

The challenge is to cope with the different physical attributes the ships have.

Enemies might be much faster than the player, or much more inert.

If I let them accelerate continuously, they are much too fast and rush by the player

and can't rotate fast enough back which makes them lose the player

(they can accelerate translational into the direction they head to and rotational left-/right)

If I take the braking distance into account, they try to approach the point where the player

is, which works, but if the player moves it results in too slow enemies because the

braking distance is higher than the actual distance to the ship and they slow down.

 

I tried vector projection, to find out how much the velocity of an enemy matches with

the direction to the player or the player's velocity, but that didn't help me either.

I hope you understood my problem: How do I take the player's velocity into account to find

the translational acceleration an enemy needs to have to chase it?

 

Here are the properties a ship has, I hope it helps you:

int Mass { get; set; }
float TranslationalAcceleration { get; set; }
float RotationalAcceleration { get; set; }
float TranslationalFriction { get; set; } // Amount the velocity vector is reduced each second
float RotationalFriction { get; set; }
float MaxTranslationalVelocity { get; set; }
float MaxRotationalVelocity { get; set; }

Here is the code for the rotational acceleration, in case you need it:

        public float ApproachAngle(float desiredAngle)
        {
            if (Math.Abs(desiredAngle) > .001f)
            {
                if (Physics.GetBrakingDistance(Math.Abs(ship.WorldRotationalVelocity), ship.RotationalAcceleration / ship.Mass + ship.RotationalFriction) > Math.Abs(desiredAngle))
                {
                    return -MathHelper2.GetSign(desiredAngle);
                }
                else
                {
                    return MathHelper2.GetSign(desiredAngle);
                }
            }
            else return 0;
        }

        public float GetIntersectionOffset(float currentAngle, Vector2 targetVelocity, float ammoVelocity)
        {
            float tangential = targetVelocity.RotateBy(-currentAngle).Y;
            return MathHelper2.GetAngle(new Vector2((float)Math.Sqrt(Math.Pow(ammoVelocity, 2) - Math.Pow(tangential, 2)), tangential));
        }

It would be very nice if you help me.

Phil


Democratic Chess

27 February 2014 - 10:04 AM

Hello Community,

some of you may have seen "Twitch plays Pokemon".

On the site there is a stream of an emulator that runs an old pokemon game. With the chat, you can press the keys of the virtual gameboy which leads to pure chaos, with sometimes 100,000 players.

 

This gave me the idea for an experiment: what would happen if two large groups would play chess against each other? Just one board and one game. Every team member can vote for the next turn. When a timer reaches zero, the turn with most of the votes is executed. When both teams are large, they would be exactly equally strong (in theory).

 

What do you think about it?

Phil


Sprite and Animation

12 July 2013 - 01:36 PM

Hello,

 

I have an Animation class that has a Sprite-Array, and of course a Sprite class that defines the actual texture.

I want to have my Entity a fixed Sprite or an Animation, when getting the Sprite and an Animation has been set,

returning the current Sprite.

 

How is this easily possible? Thought of an interface "ISprite" that only has a void GetSprite(); but this looks arwful and

it would be better to have in implicit...can one define an implicit operator in an interface?

 

Thank for your help, Phil.


Best way to implement new Items/Entities

06 April 2013 - 03:31 PM

Hello Forum,

I've started developing a medium-sized XNA game some days ago and now that I have outlined the basic structure I was wondering which is the best way to implement new Items in my game.

 

The overall structure is clear:

Characters (such as Players and Enemies) have Inventories which is basically a 2d-Array of the abstract class Item.

 

Item has four virtual functions: Load, Unload, Update, Draw.

 

There are three derivated abstract classes from Item: Weapon, Armor and Potion.

Now every derivate of these classes overrides the virtual functions of Item to implement new features.

In my game-loop Update() is called for every loaded Item in the inventory.

 

What do you think of this solution? Of course it has much to do with personal preferences, but I want to know how others would do this.

I know interfaces or abstract functions also do the job.

 

Another question would be how Entities are stored in the game's main class. Is there one big array BasicEntity[] entities or are there many, many small ones like

Tile[,] tiles;

List<Character> characters;

Pool<Particle> particles;

Pool<Shot> shots;

...

 

Thank you very much, Phil.


Calculate spaceship's movement

04 April 2013 - 03:23 PM

Hello,

 

I am currently developing a prototype of a 2d game where the user can built his own spaceships with tiles.

The player also places the jets which give him thrust to move and steer it.

In order to do that, the velocity and rotationVelocity must be calculated.

 

Unfortunately I do not know very much about physics. How can I do this?

 

Known properties of a ship:

-Velocity

-center of gravity

-weight

 

I hope my goal is not too ambitious smile.png Thanks in advance, Phil.


PARTNERS