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 / [Dark Physics] How to set local velocity?

Author
Message
Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 00:42
Hi

I want to make it so, that when I press a button, an object is created, positioned at the camera's positions, rotated to face the same way as the camera, and then add a velocity that makes it go forward(like a bullet). I've tried with 'phy set rigid body linear velocity', and set velocity on the z-axis, but then the object always goes straight forward on the z-axis, regardless of how I rotate the object.

How can I add a 'local velocity' to an object?

Cheers


Mike Johnson
TGC Developer
16
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 3rd Aug 2006 00:44 Edited at: 3rd Aug 2006 00:46
There is a demo showing how to take a rigid body and control it's position. You can find this in the Dark PhysicsDemosRigid BodiesMovement folder. It should be a good starting point for you. Basically you want to take your object, align it to the camera, create a rigid body for it and then give it a local force in a certain direction. The example will clear this up. Also check out the Forces demo for another example of how local forces work.
Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 00:47
Oh, somehow I must've missed that one... You've made me feel stoooopid...

Thanks man, I think that's what I've been looking for.


Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 00:55
I don't think that was what I was looking for after all. See, I create and set up the bullet(and rotate it according to the camera's angles), and then I call:

phy add rigid body local force ID, 1000, 0, 0, 5

just as it was done in that demo. But the bullet doesn't move at all. In fact, I can't even see it, it's not even falling down.


Mike Johnson
TGC Developer
16
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 3rd Aug 2006 01:05
Make sure you set the position of the object first and align it so it's facing in the right direction and from there fire it off. If you're not sure where the object is then use the command "phy enable debug" at the start of your program and fire up the debugger. It can be really helpful to see how the simulation views things and get a better understanding of what is going on. When time permits I'll look at creating a demo showing something like this where you can fire bullets out although it may not be too long before someone else posts a similar code snippet
Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 01:10 Edited at: 3rd Aug 2006 01:20
I'll try to check with the debugger, just to see where those bullets are actually going

Quote: "When time permits I'll look at creating a demo showing something like this where you can fire bullets out although it may not be too long before someone else posts a similar code snippet"


Sounds really nice, thank you.


EDIT: As far as I can see, no bullets are actually created. But, I have a variable that increments every time a new bullet is made. When I display the variable, I can see that it increments as it should. It's very strange...

EDIT 2 : Ok, found the problem with the dissapearing bullets. I was simply moving them so fast, that I couldn't see them before they were out of viewing range! But, now that I can see them, I can tell where they are going, and they are going straight downwards. I'll try and mess around with this for a while, maybe I'll find a way...


Mike Johnson
TGC Developer
16
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 3rd Aug 2006 01:21
Try removing the physics from things for now and check the objects you're creating. Try placing them in front of the camera to check all is okay. If that side of things is fine then go back to creating rigid bodies and continue from there.
Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 01:26
Well, I found out that the objects are appearing. I just added too much force before, so it's ok now. It's the direction of the 'bullets' that is not working. They fire now, but they are just moving straight forward as if I had used 'phy set rigid body linear velocity', ie. they are not rotating according to the camera's angles.


Fallout
16
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 3rd Aug 2006 01:43
I've not tested this so sorry if it doesnt work but try:



Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 02:26
Hmm. Apparently the bullets just fly off in different angles. If I rotate the camera the slightest bit, they go flying off in a completely different direction.


Fallout
16
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 3rd Aug 2006 11:23
Hmmm, strange. I suppose the camera vector command doesn't work as I would've assumed. Here's a cheating way that'll work for you.




Here's my silly box shooter I setup to test it:


Freddy 007
14
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 3rd Aug 2006 15:58
Thank you very much Fallout, just what I was looking for!

Cheers


Login to post a reply

Server time is: 2019-08-21 06:06:10
Your offset time is: 2019-08-21 06:06:10