Forum

Follow Mouse

25 August 2016 03:55
I was not able to find any Tutorials related to controlling the character using only the mouse.

I think I see that the tools are available but could someone help with the API code.

I'm trying to do something like this:
http://phaser.io/examples/v2/input/follow-mouse

Thanks!
25 August 2016 07:49
ok, so.. I've created a character in blender and I've applied physics accordingly.

I've exported using the project manager and got my character object floating around in space and based on the distance from the center of the screen that you click the mouse, the object flies in the direction of the mouse proportionally fast.

I'm having a problem with rotating my object in on the v_angle.

both of these methods only seem to rotate the character on the Y axis (web game engine Y = Blender = Z)
set_character_rotation(obj, angle_h, angle_v)
character_rotation_inc(obj, h_angle, v_angle)

Here is some example code to test the rotation, it works if I put my rotAngle in the angle_h postion but has no effect in angle_v)? anyone know what's going wrong?

function main_canvas_click(e) {

var myCanvas = m_cont.get_canvas();
var canX = myCanvas.width;
var canY = myCanvas.height;
var rotAngle;

canX = canX/2;
canY = canY/2;

var x = m_mouse.get_coords_x(e);
var y = m_mouse.get_coords_y(e);

x = 0.01 * (x - canX);
y = 0.03 * (canY - y);

if (x > 0 && y > 0 ) {
rotAngle = 45;
} else if ( x > 0 && y < 0) {
rotAngle = 135;
} else if( x < 0 && y < 0) {
rotAngle = 180;
} else {
rotAngle = 225;
}

console.log(canX, canY, x,y);

var myObj;

myObj = m_scs.get_object_by_name("Model");
m_phy.set_character_rotation(myObj,0,rotAngle);
m_phy.apply_velocity(myObj, x, y, 0);

Anyone know what I'm missing? maybe it's a character constraint? I could do a work around by animating in blender a rotation on the game engine Z axis (Blender Y axis) and call the animation however this is much more work.
25 August 2016 08:01
kind of going for this effect where my object rotates (on v_angle) towards the mouse.
link
25 August 2016 10:07
Hi Mike and welcome to Blend4Web forums!

This tutorial can probably help as it has info on how to rotate an object toward a point in 3D space (no physics though).
The Founder | Twitter | Facebook | Linkedin
29 August 2016 07:47
Hi Yuri,

Thanks for the welcome and thanks for the reference.. I had seen that article but after taking another look I did find some helpful things.

I'm still working to get the rotation that I want, the controls I'm trying to simulate are more complicated than I had anticipated. (using physics). I ended up using dynamic object rather than any of the character / vehicles available.. the movement on the z axis with Rigid body makes my ship do crazy things ;).

I've been using Petigors Tale for reference, got quite a bit done this past weekend, functioning damage bar, relatively matching controls for keyboard and mouse, start button ;).

Here have a look, see if it works for you. It's a 2d scroller right now in a 3d world, perhaps I'm better off to ditch the physics and just simulate them with translations?

my game solarjet is deployed HERE

HERE is another version with some textured backgrounds from the blend4web materials library
29 August 2016 07:49
Any additional references you have for getting the ship to track to the mouse in my scenario would be greatly appreciated!! thanks again.
31 August 2016 08:02
This is what I was dealing with a moon walking spaceship ;)
 
Please register or log in to leave a reply.