Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Space RTS movement - vectors?

Author
Message
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 27th Jan 2011 05:11
Hi All,

I am programming a space RTS engine and am a little hung up at the moment.
Usually I'd plug away at it and get it working, but I thought I'd ask for a little help.

I am using Ezrotate and Sparky's collision.

What I want to do is for a ship flying forwards to notice an object in it's path and turn away from it, fly past it, then turn back to it's original direction.

I am not worrying too much about waypoints and pathfinding at the moment - the code just makes the object Ezrotate to the world coordinates and move torwards them.

It spherecasts using Sparky an amount equivalent to its movement speed then gets the 3D world coordinates of the collision.
All that is working fine.

What I want to do is turn in the opposite direction (still going forwards) so if the object collides at say 50 degrees to the left I want it to turn 50 degrees to the right.

Now I can do this using normal angles - work out the opposite world coordinates on the collision (spherecast) sphere, then rotate towards those coordinates, but I am thinking that I already have the 3D world coordinates and collision normals for the collision point, which is on the spherecast radius, so I am wondering if there is a nice quick way using vectors?

(I had a little success approaching the object from one direction by using (1-collisionnormalX) etc to swap the vector over on the X axis - but it only works from one direction).

However I really want it to use all 3 dimensions. At the moment the engine is basically locked to an overhead 2D view, but it could very easily work like the Homeworld engine at this point and I want that future flexibility.

So, any advise on that problem will be much appreciated, but also any advise on the problem in general and more complicated thoughts to approach it. It seems to me though that once I have this up and running I can use as many different scripts as I want to expand the behaviour, so this is step one.

Thanks very much for any help.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 27th Jan 2011 10:11
Check out the INTERSECT OBJECT command to detect objects in your ships way.

Malevolence: The Sword of Ahkranox
The infinite RPG
http://www.msoa-game.com
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 27th Jan 2011 11:43
Thanks for the advise, but i've already got it detecting objects in its path using Sparky's sphere-casting. I have it getting the collision world coordinates what I need is this:

Imagine the sphere projected ahead of the object colliding with the object in front of it.
Looking at the sphere from the start object we can imagine the point of the collision occurring at a point on the sphere's surface.
I need to get the opposite point on the other side of the sphere, i.e to give me a set of 3D world coordinates to rotate the start object towards to avoid the object it is going to collide with.

I want it to just avoid the object though, not turn back on itself - i.e just go to one side of it, but in 3D space.

Login to post a reply

Server time is: 2026-07-16 12:19:56
Your offset time is: 2026-07-16 12:19:56