Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
I have a scene node as a bullet, and I want an object (sphereMesh1) to boost in the direction the bullet is in. If not possible, the the direction the player is facing. Here is the code: var sphere1 = ccbGetSceneNodeFromName("sphereMesh1") How would I get the parameters in ccbSetPhysicsVelocity to be the direction of the bullet (or the player if the bullet isn't a cloned object created by the Shoot action)? |
||||
|
I'm no expert, but I'd try this: ccbSetSceneNodeProperty(sphere, "Rotation", ccbGetSceneNodeProperty(camera, "Rotation") ); then apply physical force on the z axis. |
||||
|
If you mean the default bullet action in coppercube, I don't think it's possible to adjust scene nodes when they are used as "bullets". I'm pretty sure that the default "use node as bullet" action defines all the details for speed and direction of the bullet clones and prevents you adjusting it after it's fired. Instead of using the default "use node as bullet" action you could make your own bullet sequence (using the "game character" behaviour and "on proximity") to make the bullet (game character) move to it's target and do something on proximity. It's a bit of a hassle instead of using "node as bullet" but you would then be able to adjust the speed (and direction) of the node while the bullet is moving as a "game character" instead of a "bullet". I successfully managed to make a homing missile using this method, which accelerates it's speed. I just used "every few seconds" to add +1 to the player.movement speed special variable. It then continually "boosts" speed in whichever direction it's traveling. ...It works perfectly but it did take a while to sort out. So, if that's too complicated, you could ask someone nicely to make a special custom "bullet" script for you instead as several people here are great at scripting and seem quite happy to make anything you want - either for free or for a small "buy me a coffee" donation. |
||||
|
I am not really sure if this will work or not but you can try something like this.
you can change the value of speed from 1 to something else to make the sphere move faster or slower. hope that works |
||||
|
Thanks for the help, but the code gives me an error. physicsX is not defined. |
||||
|
You can define the variable physicsX, Y, Z at the top of the code, I forgot to define them sorry, I just edited the code in the previous post, try the updated code. Hope this won't give any error now. |
||||
|
Thanks for the help, but it seems like the ball will move extremely fast, or would sit there and do nothing. |
||||
|
As in my first response I had already mentioned on how to control speed, you can change the value of speed from "1" to something lower like "0.1" or "0.5", you don't need to change the value of physicsX,Y, or Z.. just need to change the value of speed variable. It also depends on the gravity of your scene, you can change the gravity of your root scene attributes. hope that helps |
||||
|
I tried fiddling with the gravity and speed, but it doesn't seem to be working. |
||||
|
Gravity and speed doesn't work with the default bullet action. |
||||
|
It's not supposed to be affecting the bullet. It's affecting a large metal ball in a huge room. |
||||
|
i know, but if you make your own bullet node (instead of using the built in bullet action) you can then add "game character behaviour to the bullet node. Then you can use the "move towards node" plugin to make the sphere node move towards the bullet node. You can't move a node to the bullet position if you use the builtin bullet action - until the bullet has hit a target. |
||||
|
@Kierham, I am Sorry, however, the above code is correct but as it is written directly in the forum text box, I wrote in a fashion I don't usually write my codes into, I just tried the code myself and it didn't work for me either, It was positioning the sphere mesh to an undefined position. I rewrote the same code in visual studio in a different manner, and tested it, it works completely fine now. as you can see the code is the same as the above, it's just the writing manner that is different. Use the below code and you are good to go. Make sure that the physics engine is turned ON and your sphere mesh has a collide when moved or object moved by physics engine behavior attached to it.
Hope this is what you wanted to achieve cheers |
||||
|
This worked! Thanks! I will credit you in my game if I finish it. I also wanted to tell you that I had to set the speed to a negative number. I did this because I would get run over by the ball if the speed was a positive number. |
||||
|
Thanks mate, I am glad it worked for you, and if you are willing to put my name in your game, then I would like my real name to be used, you can put something like "Vazahat Khan (Just_in_case)". You could have also limited the area so that you won't get run over by the ball. As you wanted to have done it on a physics object, I created the above script for you, but if you ever want to use a more advanced feature-rich behavior, then you can use "AI Behavior" that comes with my Beat'em up the game project. Download the project from here. https://neophyte.cf/ccb_source_b... |
[ 1 2 ] Page 1 of 2 |
|