• Create Account

# Grimshaw

Member Since 03 Jan 2011
Offline Last Active Dec 17 2014 01:08 PM

### Starship auto steering

20 October 2014 - 06:25 AM

Hello,

I have been programming games for some time now, but one thing I never really fiddled with too much was AI and clever steering behaviors.

I am currently implementing a game where you control 3D space ships along a 2D plane, using a point and click based system.

Movement of the units is really simple, they have a current transform and every tick they move towards their "goal" position in a straight line (if there is a goal position; otherwise the ship is just idle). As the ship translates into the final position on this 2D plane, it rotates at a given speed to face the target, so it doesn't feel too abrupt, for example as when the user tells the ship to go to somewhere in its behind area.

Now, I want to give my ships a bit more interesting movement. I am not touching the basics of the movement, it remains a simple point and click to make the ship go from a transform A to transform B, but I want the ship to traverse a more interesting path to get to the destination, respecting some local mobility rules of the ship itself.

Can you give me some guidance on how to tackle this issue? I am not sure what to look for, perhaps there are some well known algorithms to handle this?

Otherwise, what would be my next step, assuming I don't get any hints, would be to try and model some basic elements of a big starship, and try to play with those in how the ship moves.

1) Tilting: the bigger the ship, the less tilting it can do as it moves, and because of this, it also turns slower if it can't tilt. Tilting of the ship would vary depending on the dot product between the desired direction and current direction , in relation to current speed?

2) How much lateral/backwards thrusting power the unit has, which would influence how quick it can turn to face the target direction? (assuming there is any; some ships could simply have a unique propulsor at the back)

3) General mass of the ship would come into play with its thrust power to decide how quick it moves?

### Forward declarations

12 July 2014 - 06:17 AM

Is there any chance (or did I miss it somehow?) that angel script could support forward declaration?

Like defining classes in a different place from the declaration:

class A

{

void helloWorld();

}

void A::helloWorld()

{

}

Is something like this going to happen?

### How to make classes and objects from another module accessible?

02 July 2014 - 06:08 PM

Hello,

I know I asked a similar question before but I still have one doubt.

So, my game has N states (individual screens like pause, menu, game etc) and each one lives in its own module and communicates with other states exclusively using a central queue, so all information gets to the destination indirectly.

But now, I also added behaviors to the engine, where each behavior is a script that controls an entity's behavior. For example, one behavior script might give an artificial intelligence to the character, another just make it follow a path etc.

For now, each behavior is a custom class, such as class MyBehavior : Behavior {}, and is also living in its own module and loaded from its own script file, which works fine to deal with its attached entity and give it behavior. However, now I need that my game state script is able to retrieve data from any of this behaviors currently instanced, like:

// this is the game state script

behaviorClass@ behaviorObject = cast<behaviorClass@>( GetBehavior("entityName", "behaviorClass") );

behaviorObject.x = ; // set or get variables declared in the external file of the given behavior

I'd like to add that the behaviors are hot reloadable, so I basically shut them down and re create them once the script source has changed, in order to have the most recent version running in the game without re-running the process. Is there a way to do something similar to this with AngelScript? I am not sure if the game state script module could either dynamically bind to these external behavior classes or just remove and recompile the code sections respective to the behavior scripts so they are in scope, while operating on instanced objects of behavior classes created in the other module.

As a second question, just wanted to ask if there is a way to associate member variables with the pure angelscript interfaces. I basically want that when I implement a new behavior, as it inherits the interface Behavior, it would automatically inherit a member Entity@ attachedEntity, so even if my custom behavior class has no members it still knows about which entity that instance is attached to. I am asking as I didn't see any C++ api function to do this, interfaces seemed to only be able to define the virtual methods and actual interface name,

The solution I thought about was to define myself a base class that is actually a angelscript class rather than an interface, this way I could do anything to it and pre-implement functions etc, is this the way to go?

Is there any chance you can implement in the future some kind of explicit and/or implicit conversion mechanism when calling a function? Like MyBehavior@ a = getBehavior<MyBehavior>() or have it return instead an abstract handle to the base type that can be automatically casted to the expected type of 'a'? I am talking about doing these with only script classes here

### Inter-module class access

24 May 2014 - 04:45 AM

Hello,

I am currently trying to solve an issue and I'd like some direction on the best way to handle it.

In essence, my game has a few states (intro, loading, menu, game, pause, etc), each state is a unique class defined in a unique file, and they all inherit from a common interface GameState.

Right now, I am compiling each class into its own module, which creates the problem that I can't access classes from other modules and I need to do things like that, for example, the loading script would get the handle to the game script object, and would change some values in that state object for game initialization.

How should I handle this? Move all classes to a single module so they can access each other mutually? Should I use a messaging system instead? Is there any other recommended way?

Also, in case of maintaining a single module for all my classes, besides avoiding name collisions, should I have any other concerns? Is there a problem if I add later other classes into this module, whenever there is the need?

Thanks

### Is there a bug with function callbacks?

10 April 2014 - 05:34 AM

Hey,

My use case is really simple, I have a button object, which holds a asIScriptFunction pointer with its callback in a script, called when the button is clicked. If the button is clicked and the function is NULL, it does nothing, if it is a valid function, it calls it so the script can react to the event.

I did everything like the manual but I get a compilation error. First, I registered my funcdef:

asx.get()->RegisterFuncdef("void UICallbackFunction()");

Then, I register my UI connect function to bind buttons to script functions:

asx.get()->RegisterObjectMethod("UICanvas", "void connect(const string& in, UICallbackFunction @cb)", asMETHOD(UICanvasScriptInterface, connectClick), asCALL_THISCALL);

The connectClick() method has the following signature: void connectClick(const String& name, asIScriptFunction* callback)

And, in the script, I am doing this: ui.connect("myButton", onMyButtonClicked); , where onMyButtonClicked is a void onMyButtonClicked() function. It all seems pretty much like the manual, except im registering the callback through a method instead of a global function.. right?

What is wrong? My compilation error is as follows:

ERR: No matching signatures to 'UICanvas::connect(const string, onMyButtonClicked)'

INFO: Candidates are:

INFO: void UICanvas::connect(const string&in, UICallbackFunction@)

The funcdef indeed has the same signature as the target callback function..

EDIT: I actually tried to make it all like the manual: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_callbacks.html . Same problem

My regards,

Artur

PARTNERS