# 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.

### Dark Physics & Dark A.I. & Dark Dynamix / calculating "set rigid linear velocity" parameters

Message
Posted: 27th Mar 2011 23:43
Hi guys, complete noob here so forgive me if this has been answered already but I couldn't find it using the forum search.

I'm trying to use the "linear velocity" function to power a projectile which is fired from a cannon. The canon orientation is variable so I am trying to calculate the values needed for the "linear velocity" command from that.

The following code creates the cannonball (proj) at the base of the cannon (plobturret), makes it a rigid body sphere, then fires it out (for the minute using values 10,10,10 as the parameters). Obviously these are the values I need to calculate based on the cannons position and orientation.

The problem is for the life of me I can't work out how to calculate an x,y,z linear velocity value based on the angles of the cannon.

I'm completely stuck on this and any help would be gratefully recieved.
Posted: 28th Mar 2011 02:14
hey do a quick search in google...you will definitely got lot's of info about "linear velocity"

Posted: 28th Mar 2011 11:38

Yeah I know what I want to achieve and how linear velocity affects an entity, I just don't know how to implement this in DBPro.

I can't just take the angle of the cannon and use that, because that would mean that the projectile would shoot out with more force the higher the cannon was tilted. Obviously this is wrong.

There must be an algorithm that can calculate the required x#,y# and z# paramaters for this command if it's given the x,y & z angles of the cannon.

I just can't work out what it is
Posted: 28th Mar 2011 12:03 Edited at: 28th Mar 2011 12:04
think you will need to rotate the object(bullet) with phy rotate so that it is facing the direction you wish it to fire then it should go in that direction.

meaning if your turret is facing 270 and up 35 then rotate the object to that before you press fire.

what you might not have notice if you use -10 on the phy set rigid body linear velocity proj, 10, -10, 10 in will go downwards.

its a bit like hitting a softball, depending where you hit the ball with the bat is the direction it will go in.

Dark Physics makes any hot drink go cold.
Posted: 28th Mar 2011 12:47
give this a go you may see what you want in it.

Dark Physics makes any hot drink go cold.
Posted: 28th Mar 2011 12:55
Thanks for the replies, I'm sorry I appear not to be replying, I'm still at that stage where a moderator needs to approve my post

I can't find any reference to a phy rotate object command, I'm wondering if it might have been present in an older version but has been removed now.

Your code snippet is pretty much what I have now. No matter how you rotate the camera, the ball still shoots in the same direction. I'm trying to get it firing relative to the position of the cannon. So using your code example, if you could get the ball to always fire directly away from the camera, no matter which direction the camera is looking, that's pretty much what I'm after. I could adapt that code to suit if you could figure that out

Thanks for your help with this by the way.
Posted: 28th Mar 2011 16:47
As this is a major stumbling block for the development of my program, I've coded a non-physx solution for now which works perfectly. Of course I have to manually handle all the associated variables but it doesn't seem to have slowed the routine down much though.

So I'd still very much appreciate a solution (I can't believe it's this hard to fire a projectile from a cannon!) but it's less of a priority now as I have found a workaround
Posted: 28th Mar 2011 19:34
show me your work around and I'll see if I can plug it into the above code system.

the phy rotate and also position.

PHY SET RIGID BODY POSITION
PHY SET RIGID BODY ROTATION

Dark Physics makes any hot drink go cold.
Posted: 28th Mar 2011 19:45
Here is the routine which covers the movement of the cannonball..

The "lasttime" variable is just a snapshot of the system timer when the cannon was fired.

"shellspeed" is the velocity of the cannonball.

Basically, I'm just pitching the object down a little with each iteration of the subroutine, this gives a very similar look and feel to the effect of gravity. Of course I can tweak the amount it's pitched by for different gravity effects, but a value of 1 seems to work quite well.
Posted: 28th Mar 2011 21:09
let see if I have the info correct, you have a tank cannon which can move around the ground in any direction with the camera following it or staying at a distance.

So in theory you could shoot the camera if you lined the barrel of the tank with the camera and fire the sphere would be shot towards you and the fly pass (duck).

Have I got this right?

from what you show above, it looks like you took the sphere out of the physx system am I correct on that?

Dark Physics makes any hot drink go cold.
Posted: 29th Mar 2011 03:01
Yes I am not using the physx system at all at the moment, mainly because what I thought would be the simplest of functions, turned out to be a lot harder than I imagined

The workaround is great, and depending on how the program progresses, I might end up using that for everything. My aim is to eventually go multiplayer, but only testing will tell how it holds up to that.

You generally have the idea, but the cannon could never shoot directly into the camera because the camera is always following behind.

..to give an idea of what I'm trying to achieve. If you can imagine that, except with the projectile being controlled via physx rather than directly. Although to be honest, it plays and feels fine now

(Fraps is limiting that to 30fps by the way, in reality it plays at 60fps synced.)
Posted: 29th Mar 2011 16:41
looks good and just in its basic mode, wonder what it be like when you've WOW it up.

Dark Physics makes any hot drink go cold.
Posted: 29th Mar 2011 16:49
Thanks

I'm just working on the collsions a bit more and adding some sound, then I intend to make it look a bit prettier