Forum

How to control speed and direction of a moving object?

30 January 2016 20:10
I have created the following setup using the new Transform Object node. This causes the object to begin moving when clicked.


speed_and_direction.blend

I would like to control the speed so that it gradually accelerates and decelerates. I would also like to be able to steer it using input from the keyboard.
Thanks in advance for any help.
01 February 2016 11:51
In addition to the Transform Object node, I have also done some experimenting with the Move To node.

One effect I have been able to achieve is creating a self-propelled missile that chases an empty in front of it. Since the empty is parented to the missile it remains in front of it forever, and the missile continues to chase it forever.
To my surprise, key-framing the empty to gradually get closer to the missile did not cause the missile to slow down over time.

missile_self-propulsion.blend

In a second experiment I had the missile seek a target. The target will also move when clicked, so that the missile can be fired at it again. In order to keep it in view, the camera also gets re-positioned each time this happens (although the distance seems to have some variation each time).

missile_seek_target.blend



I don't know how "on target" my approach is though in terms of being usable in a game, because none of this takes physics into account. But it's the most I could figure out so far using only the Logic Editor.
01 February 2016 12:02
Hello!

I would like to control the speed so that it gradually accelerates and decelerates
You can for example use variable for duration parameter in your transform node and increase/decrease it in loop
I would also like to be able to steer it using input from the keyboard.
For now there is no way to use keyboard input directly from logic editor. It requires JavaScript coding.
Blend4Web Team - developer
Twitter
LinkedIn
01 February 2016 12:15

You can for example use variable for duration parameter in your transform node and increase/decrease it in loop
Thank you, Konstantin.
I was not able to get the variable to accept a non-integer value. I tried 0.5, 0.1, etc. but it did not work. What is the correct way to do this?
01 February 2016 12:23

I was not able to get the variable to accept a non-integer value. I tried 0.5, 0.1, etc. but it did not work. What is the correct way to do this?
I got it!
It is a terrible bug
If you use non integer variables for Y or Z translation/rotation their decimal parts will be ignored.

So sorry for that!
We'll fix it in the nearest release
Blend4Web Team - developer
Twitter
LinkedIn
01 February 2016 13:04

I don't know how "on target" my approach is though in terms of being usable in a game, because none of this takes physics into account.
Move To takes physics into account. Physics properties for each object are declared in specific panel, you can find info in docs:
https://www.blend4web.com/doc/en/physics.html
Blend4Web Team - developer
Twitter
LinkedIn
01 February 2016 15:25

I got it!
It is a terrible bug
If you use non integer variables for Y or Z translation/rotation their decimal parts will be ignored.

So sorry for that!
We'll fix it in the nearest release

Ah, I was wondering if it was a bug. I guessed it was more likely my lack of understanding.
This is good news that I could help with discovering a bug! No need to apologize.

Move To takes physics into account. Physics properties for each object are declared in specific panel, you can find info in docs:
https://www.blend4web.com/doc/en/physics.html

This is really good to know!

Thank you, on both of these points!
01 February 2016 15:54

One effect I have been able to achieve is creating a self-propelled missile that chases an empty in front of it. Since the empty is parented to the missile it remains in front of it forever, and the missile continues to chase it forever.
To my surprise, key-framing the empty to gradually get closer to the missile did not cause the missile to slow down over time.
Sorry, can't find any key-frames in blender. If i understand everything right, you want to animate empty to get missile move slower and slower with time. So you need somehow start this animation (apply default or with logic node or some other way)


This is good news that I could help with discovering a bug! No need to apologize.
Oh… forget to thank you for the help, of course! I am just really frustrated to have bug in such an important node.
Blend4Web Team - developer
Twitter
LinkedIn
01 February 2016 19:12

Sorry, can't find any key-frames in blender. If i understand everything right, you want to animate empty to get missile move slower and slower with time. So you need somehow start this animation (apply default or with logic node or some other way)
In the .blend files I attached, the empties are not key-framed. Sorry I wasn't clear about that.

Regarding my larger objectives with this, I want to accomplish a few different things in a flight simulator game:

1) Planes should fly (Sounds simple, but I think it will be quite tricky. Evgeny has offered me some advice, but I'm still too much of a newbie to implement it.)
2) The planes should be able to shoot missiles and fire machine guns. Experimenting with methods for doing this was the purpose of this thread.
3) Missiles and other weapons should cause damage. I haven't reached this point yet.

This is currently way beyond my level of ability, so I have been doing some experiments and trying to learn B4W one piece at a time. There is a project I have in mind after this too, but I have to learn a lot more before I can even attempt it.
01 February 2016 21:59

This is currently way beyond my level of ability, so I have been doing some experiments and trying to learn B4W one piece at a time.
I think it is a wonderful starter project idea. There is no serious flight simulators of any kind yet on b4w. So it will be really interesting for us to keep track of your app and help to solve problems which you will face

Blend4Web Team - developer
Twitter
LinkedIn
 
Please register or log in to leave a reply.