ArrowCustomControl

Hi guys,

first of all, I am new to JME and i have to thanks houndreds times all people involved in this project for their great job!!

I’m italian so sorry my english if is not enough correct XD

You are just the best!!! :wink:

In this my first topic in the forum, i wanna ask a little help about CustomControl(s):

i need to understand how to do something like “mouse picking” using the eventListener instead of rayCasting.

For instance, i need to do a control that controls an arrow that can attachs itself to the mesh it collide with, so in the collide(PhysicsEvent event) method i need to take the point of the collision and attach the arrow like the sphere spatial in the example of mouse picking.

How i can do this?

If it is also possible i wanna attach the arrow to the mesh with the angle it collide with, for a more realistic effect.

How can be done a thing like this?

I hope it is understanable what i’ve write here XD

Thanks for all hands… :slight_smile:

Drael

Ok, the method does its job!!

So when the arrow collide with an object a attach the arrow to the object node at the collision point.

Therefore, I don’t now how to launch the arrow in the corect way, like a real arrow. Infacts when i launch it, the position is always horizontal because i create the arrow in this way.



Can you tell me how a can make the arrow to follow a path where the inclination is as real as possible?



I thought also that when i create the arrow i have to make an appropriate collision shape because in this moment i use a capsule shape instead of a mesh shape or similar. But i don’t now how to do this…



And i wandering if is possible to attach the arrow to the node of the object it collide with, with the same angle of the impact…



Thanks for you answers :slight_smile:



Drael

you can find the point of collision on each object using event.getLocalPointA() and B if i remember correctly. I don’t think you need to merge the meshes for that, you can just create a node and attach the player and the arrow to it, and the arrow will stay in place when you translate the node.

Yeh that is possible, you could even use the built-in physics in the engine, by applying an angular or linear velocity, or you can look at the equations of motion for doing it yourself. A capsule shape is probably fine, for an arrow, i think moving objects should always use simple collision shapes, or a compoundcollisionshape. And yes you can keep the angle of impact. I really suggest you re-read all of the tutorials docs, and @normen 's most favorite links:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

Thanks for your support,

now i’ve understood how to correctly rotate the arrow, but:



if i have the collision point, how can i retrieve the angle betwwen the surface it collide with and the arrow itslef?



And i suppose that until i find a way to make the path of the arrow more realistic, it will never be in the correct position when colliding… infacts the arrow seems to be a capsule that holds its position when thrown, but an arrow should follow thw direction of the peath, thing that it does not do right now.



So how can i make the arrow to be really influenced by something like the air that makes the arrow to follow the correct and more realistic path?



Sorry me if i’m not sure how to explain myself XD however i prefer to use the tools of the negine instead of calculating the path and angles myself because i’m sure it will be more accurated if i do this myself, but can be more performance made by the engine.



Thanks a lot monkeys!!! :slight_smile:

I was wondering a possibility:

If i delete the ghostObject and the physicsControl when the arrow collide, and attach the arrowNode to the node it collide with,

Is there a possibility that the arrow helds its position?

Just use a box collision shape for the arrow, and apply a force to keep it pointed in the direction of travel. The arrow’s trajectory is parabolic, so this will simulator an arrow’s fins providing the aerodynamic stability. When it connects, just get the rotation and translate it to the contact point with the rotation.

Eh…

I’m tring to do this but i can’t find a way…

For example i don’t know how to get the collided ojject…

Can anyone tell me what should i do in the public void collision(PhysicsCollisionEvent event) method please?

Because i know what to do but i don’t know the code to use…

Thanks a lot :slight_smile:

i check collision by looking at the applied impulse, if > 0 its collided with something physical and thus bounced off, when i have that i simply find what object collided with it, heres a segment of code i use;



[java] if(event.getAppliedImpulse() >0 && this.isActive()){

try{

Spatial temp;

this.active=false;

this.remove();

try{

temp = event.getNodeB();

if(checkCollision(temp, event.getPositionWorldOnB())){

return;[/java]

[java]package it.mygame.control;



import com.jme3.bullet.collision.PhysicsCollisionEvent;

import com.jme3.bullet.collision.PhysicsCollisionListener;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.bullet.collision.shapes.CollisionShape;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.objects.PhysicsGhostObject;



/**

*

  • @author DraEl

    */

    public class ArrowControl extends RigidBodyControl implements PhysicsCollisionListener {



    private PhysicsGhostObject ghostObject;



    public ArrowControl(CollisionShape shape, float mass){

    super(shape,mass);

    createGhostObject();

    }



    @Override

    public void collision(PhysicsCollisionEvent event) {

    if(event.getObjectA() == this){

    }



    if(event.getObjectB() == this){

    }

    }



    protected void createGhostObject() {

    ghostObject = new PhysicsGhostObject(new CapsuleCollisionShape(1.0f,10.0f));

    }

    }[/java]





    Ok, this is my class. What have i to do? checkCollision seems to not be a method inerited …

    Thanks really a lot for you support!!



    DraEL

checkCollision is my own method, you have it in spatial form, now you check that spatial for certrain properties, i check if its called “player_node” then do something based upon it, i.e. (a fireball instance) does dmg to the player. etc



[java] public boolean checkCollision(Spatial s, Vector3f point){

if(s.getName().endsWith("_EnemyNode") || s.getName().endsWith("_PlayerNode")){

this.getPhysics().findPlayerViaNode(s.getName()).dealDamage(this.getDamager());

return true;[/java]

My intent, is to launch an arrow that can be attached to an object when it collide with that…



I don’t have to implement some particular behavior if it collide with a certain object. Every object the arrow collide with have to be attached by it.

Another big problem is that i’m confusing how to launch the arrow because i’ve tried some kind of forces to apply it but the result is always the same and is not what i’m tring to do. And a thing i can’t understand how to do is to make the arrow look at the path of a realistic arrow…



I know my eglish is not enough understandable XD but i don’t know how to explain myself with this kind of ArrowControl i’m tring to code.

But you can think it as ALL THE CODE THAT MAKE A VIRTUAL ARROW A REAL ARROW XD

Infacts a real arrow have the metal part oriented to the parabole the arrow is following, (how can i do this?) and when it collide with an object it will penetrate the object’s surface. The last thing is that i want to launch the arrow in a ealistic way, where it is oriented to the camera direction…



So, this is the behaviour i want to implement :wink:



Help me please!!!

Up…

I would say you should use forces to move the arrow, and manually adjust the rotation of the arrow knowing the acceleration in the y direction. If your doing a sort of parabola, then when there’s no acceleration for example you know that it should be facing parallel to the x axis. Then as gravity pulls it down the acceleration changes and you can rotate it accordingly. On a collision with a player, if your player is already in a node, then couldn’t you just do. playerNode.attachChild(arrow); arrow.setlocaltranslation(event.getlocalPointA) or use worldtolocal on the arrow, or something like that. Saying “Up…” just annoys people, don’t do it

Ok, i know i should use forces, but it’s not easy to understand how to use those…

If i want to apply a force to the arrow i’ve to specify the poit but how can i do this?



In the case i hit something with an object i can get the impact point and then apply the force to it, but in case of an arrow htere’s no way i can do this thing. However simulate the traiettory of the arrow hard coded is not a good idea imho because if there are 10 arrows in the space the risk of latency increase considerably. And if this control will be used in a networked game it could results in a disaster…



In your opinion, wht about if i create 2 shapes that rapresents respectively the stick and the tip of the arrow, and attach it each other with different masses?

Could it follow a correct path?



Afetr this problem yet, remains the question about how to apply forces to the arrow and if you want, can you write the code to do the necessari things to attach the arrow to a node with the angles it collide?



Thanks a lot!!! :slight_smile:



PS UP nevere again!! :wink:

perhaps this method may help setAngularFactor(). This supposedly rotates the spatial, I’ve never used it so I can’t be certain of its outcome. I’ve never done an arrow before so I’m not sure exactly what you need for it.



[java]arrow.getControl(RigidBodyControl.class).setAngularFactor(0.25f);

arrow.getControl(RigidBodyControl.class).setLinearVelocity(Vector3f.UnitY);

arrow.getControl(RigidBodyControl.class).applyforce(direction, location);[/java]



I can’t be of more help sorry, this isn’t my strong suit, i normally just implement the behavior I want using equations of motion. Just try mixtures of the available forces until you get something you want.